Docker Compose is a tool that allows you to deploy an application composed by multiple containers. For example, imagine that you want to deploy Joomla. It requires two containers, the web application (which it also runs the web server apache) and the database.
Deploying using the docker CLI
First, let’s deploy Joomla using the Docker command line interface.
- Run the database container. We do it first because the database is a dependency of the application.
1 |
docker run --name db -e MYSQL_ROOT_PASSWORD=my-secret-pw mysql |
- Run the application container, link it to the database and map the port 80
1 |
docker run --name my-joomla --link db:mysql -d -p 80:80 joomla |
Executing containers in the background
The previous commands allows you to run the containers and all the logs will be shown in the terminal. If you want to run the containers in the background, you need to add the parameter -d
1 |
docker run -d --name db -e MYSQL_ROOT_PASSWORD=my-secret-pw mysql |
Stopping containers
If you want to stop and delete a running container, allowing you to start another container with the same name, you just need to execute the following command. The last parameter is the container name.
1 |
docker rm -f db |
NOTE: you can get the name of all running containers executing the command docker ps )
Installing Docker
You can install Docker by executing the following command:
1 |
curl -sSL https://get.docker.com/ | sh |
Deploying using Docker Compose
Docker compose makes things more simple. It allows you to create a simple YAML file that will contain everything required to orchestrate both containers. Let’s run the previous example using Docker Compose.
Create a file called compose-joomla.yml with the following content:
joomla:
1 2 3 4 5 6 7 8 9 10 11 |
image: joomla links: - db:mysql ports: - 80:80 db: image: mysql environment: MYSQL_ROOT_PASSWORD: example and run docker-compose up docker-compose up |
Installing Docker Compose
If you do not have Docker Compose installed yet, you can do it by executing the following commands:
1 2 |
curl -sL https://github.com/docker/compose/releases/download/1.5.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose |
Deploying Containers in the Cloud using Manageacloud
First, in our account, we create a server configuration, called docker_compose_joomla, using shell, for Ubuntu 14.04 and using the following content:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#!/bin/bash set -x # enable debug # install docker curl -sSL https://get.docker.com/ | sh # install docker compose curl -sL https://github.com/docker/compose/releases/download/1.5.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose # add the configuration for joomla using Docker Compose mkdir ~/compose-joomla cat > ~/compose-joomla/docker-compose.yml << EOL joomla: image: joomla links: - db:mysql ports: - 80:80 db: image: mysql environment: MYSQL_ROOT_PASSWORD: example EOL # execute both containers cd ~/compose-joomla/ && /usr/local/bin/docker-compose up -d |
Running applications in the cloud
A server configuration is everything that is required to run applications in the cloud using Manageacloud.
Deploying from the web interface
There are two ways to deploy a server from the web interface:
- By clicking “Quick Deployment” from the server configuration view
- By clicking “Production” or “Testing” from the advanced deployment page
Deploying using the mac cli
You can also deploy from the command line interface:
1 |
mac instance create -c docker_compose_joomla |
Installing mac Command Line Interface
You can install mac cli by executing the following command:
1 |
curl -sSL https://manageacloud.com/mac | bash |
Deploying using Manageacloud triggers
The mac cli and the web interface requires credentials and some other minor tweaks to run. However, if you use triggers , you will isolate all that complexity. You can deploy just by executing a POST into an URL.
- First, create a new trigger at you account
- Comment out the lines that contains the credentials:
1 2 |
export MAC_USER=[...] export MAC_APIKEY[...] |
- Add the following line to the trigger
1 |
mac instance create -c docker_compose_joomla |
Now you can run the trigger, deploying the application, just executing a POST to an URL. Example:
1 |
curl -X POST https://manageacloud.com/trigger/my_trigger_65rov8bpp6pl8dr |
Triggers and Webhooks
Triggers are bash scripts that isolates all the credentials and complexity. Triggers are specially ideal to run in Webhooks as part of the Continuous Integration or Continuous Deployment pipeline.
Deploying using macfiles
Sometimes is just not good enough to deploy single servers as you need to use infrastructure resources such as load balancers, autoscaling groups and more.
macfile is a technology agnostic framework that allows you to integrate any technology that uses bash . Access to the quickstart guide for more information.
Deploying using API
If you want to integrate the deployment of Joomla with an application, you should use the API to create the server. For example:
1 2 3 4 |
$ curl -X POST -i -H "Content-Type: application/json" \ -H "Authorization: ApiKey username:myhashedpass" -d \ '{"hardware": "512mb", "cookbook_tag": "docker_compose_joomla", "location": "sfo1", }' \ https://manageacloud.com/api/v1/instance |
Deploying using Manageacloud scripts
Sometimes you need to deploy server configurations in existing servers. In this case, you can deploy using the Manageacloud script, accessible from the deployment page. For example:
1 |
curl -sSL https://manageacloud.com/api/cm/configuration/docker_compose_joomla/ubuntu/manageacloud-production-script.sh | bash |
When should I use Manageacloud scripts ?
You can use Manageacloud script in many different cases, for example:
- In the Dockerfile to create the configuration of your container
- If you create development servers using Virtual Box
- and more
Conclusion
Docker Compose is a fantastic tool to deploy containers and microservices in the cloud. Using it along ManageaCloud offer us the flexibility required to deploy applications in the cloud, covering many different use cases and deployment scenarios.
- Advanced Ways to Improve Your Site’s SEO - September 29, 2017
- How to Optimize DotNetNuke speed by improving page load, caching and use of CDN - September 28, 2017
- How to solve Joomla is not able to install the extensions - September 27, 2017