Here is a guest post from Ivica Nedeljkovic from Intelestream which is one of our new SugarCRM Partners. In this post, Ivica explains how you can use Intelestream created Docker containers hosted on DockerHub to easily deploy Sugar.
If I was asked to list the top five technologies in the last 5 years, Docker would certainly be on the list.The real advantage that Docker containers have over other server virtualization software is that Docker uses shared operating systems instead of trying to virtualize hardware. This takes less resources, is easier to boot, and faster to spin up instances.
Some performance issues were experienced with Docker containers on OS X and Windows and some security issues were also experienced because up until Docker version 1.12. Until Docker 1.12, the native OS X/Windows virtualization options were not used and 3rd party Linux virtual machines such as VirtualBox were used instead. For virtualization, Docker 1.12 for Windows uses Alpine Linux on top of a Hyper-V VM and Docker 1.12 for Mac OSX uses Alpine Linux on top of a xhyve Virtual Machine.
Docker 1.12 was released in July 2016. In addition to boosting performance it also simplifies the whole process of creating new containers, as you no longer need to use a docker-machine anymore to create virtual machines.
For this project, we store Docker container images on DockerHub. DockerHub allows developers to use pre-built images that are stored in the web repository. Additionally, every time a developer makes a change to a Docker config file, these changes can be pushed back to DockerHub to generate new automated builds. This simplifies the process if you want to deploy your container image on a number of servers. For example, you can set triggers and hooks. DockerHub allows you to have a number of public repositories and one private repository for free. If further private repositories are required then additional packages can be purchased.
We are using docker-compose to create different containers for web app (php 5.5, Apache), db server (Mysql 5.6), Elastic Search (required for the professional version). As a bonus we added a container with phpmyadmin that you might need to manage a mysql databases.
Launching Sugar using DockerHub Containers
Follow along to start using Sugar via DockerHub containers.
Step 1: Install Docker 1.12 or later
This is a recommendation and not a requirement. An older version of Docker or Docker Tools can be used, but in such a case you must use a docker-machine command to create a virtual machine for Docker to run inside and set environment variables. Should you choose to run one of these options instead of Docker 1.12 you will notice that the remaining steps are similar to those listed below.
Step 2: Clone intelestream/sugarcrm-docker.git repository
git clone email@example.com:intelestream/sugarcrm-docker.git
In case you already have some service listening on ports 80 (Apache), 3307 (MySql – custom port), 9200, 9300 (Elasticsearch) or 8181 (PhpMyAdmin) please disable them. Alternatively, you can also modify these ports in the docker-compose.yml file for all of these services, with the exception of the web server port. Sugar uses the file_get_contents command which does not work with ports (just for checking installation requirements).
Step 3: Run docker-compose to start images
Using the console, navigate to the folder that has been created and type:
This command will download all images from the DockerHub and start building containers. Spinning up containers for the first time will be fairly slow but as soon as all images are downloaded then the process will speed up considerably.
Once everything is completed, you should have containers with Apache, MySql, and Elasticsearch running. To stop/pause them, use “CTRL+C”
At this point all services should be running. Our public web folder is www. To check if everything is running as expected you can test by creating a test.php file under there and accessing it within your browser:
Step 4: Place Sugar code and run Sugar installer
Copy Sugar application code to the www directory and place it in a directory named sugarcrm. The system is designed for developers to be able to have more than one instance of Sugar. All you need is multiple individual databases.
Open http://localhost/sugarcrm (or whatever name you decided to assign to the above folder) and enter the following in the Sugar installation wizard:
(The host needs to be mysql_crm, it will be resolved by docker. See docker-compose.yml)
DB Name: sugarcrm
DB User: sugarcrm
DB Password: sugarcrm
root user: root
root password: sugarcrm
Elasticsearch Host: elasticsearch_crm
(See host again in docker-compose.yml)
Elasticsearch Port: 9200
Sugar is now up and running! Happy coding!
Below are some tips for working with this server set-up.
Accessing the MySQL database
phpMyAdmin is installed if you need to administer your MySQL database. You can access phpMyAdmin by opening the following url:
Accessing a command line for a container
In case you need to access any containers:
This lists all of the containers and their IDs.
In the command below replace container_id with the container id you want to connect to based on the results of the previous step:
docker exec -i -t container_id /bin/bash
Setting up Cron from command line
First, retrieve a command line for your Apache server instance using the previous steps. Then to set up a cronjob, run the following line:
cd /app/www/crm; /usr/local/bin/php -f cron.php > /dev/null 2>&1
And start Cron service:
service cron start
If you shutdown and remove container, you will need to set up the cronjob again for new instances.
- When you repair and rebuild your caches, you will notice a decrease of around 40-50% in terms of speed in comparison with an instance of Sugar running directly on the host, because many files need to be written and synced between systems. If you do not do this action too often you will not notice a big difference between performance
- If you do not need all containers, you can comment those you do not need in the docker-compose.yml file. For example, if you do not want to use both the web server and MySQL server because you can use them from your local host, then you can simply have only Elasticsearch running in a container so you do not need to install it. Even simpler, you could just download the Elasticsearch image from the official repository on DockerHub and start it!