Docker orchestration is a term used to describe process of managing multi-containers and their configuration on the same host or across a cluster.
One of the most important tools in this ecosystem is Fig, fig is used to automatically setup an entire environment using docker containers with simple steps. Fig is developed by Orchard team and later acquired by Docker Inc.
In the last Post, I used 5 docker containers to create a simple WordPress-Nginx application, in this post i will fig to automate the process of creating and wiring together these containers.
Fig is written in python, so you can install it using pip, or downloading the binary from github:
# curl -L https://github.com/docker/fig/releases/download/1.0.1/fig-Linux-x86_64 > /usr/local/bin/fig # chmod +x /usr/local/bin/fig # fig --version fig 1.0.1
Fig uses a YAML file that contains the information about the containers to boot up and also their configuration.
To build the images and launch the multi-container application, we create the fig.yml and specify the containers and their links between each other:
# cd docker-wordpress-nginx/ # vim fig.yml nginx: build: ./nginx/ ports: - "80:80" volumes_from: - downloader links: - app1:app1 - app2:app2 app1: build: ./fpm/ volumes_from: - downloader links: - mysql:db app2: image: dockerwordpressnginx_app1 volumes_from: - downloader links: - mysql:db mysql: build: ./mysql/ downloader: build: downloader/
Each container is called service in fig world, here we defined 5 services nginx, app1, app2, mysql, and downloader. The nginx service will be equivalent to run this command with docker:
# docker run -d -p 80:80 --name nginx --volumes-from downloader \ --link app1:app1 --link app2:app2 husseingalal/nginx
After creating the yaml file, its time to boot up the containers and start the music using fig up:
# fig up -d
Using -d to demonize the containers and run in the background. Fig aggregates the logs of all the containers in one place and you can see that by running:
# fig logs Attaching to dockerwordpress_nginx_1, dockerwordpress_app2_1, dockerwordpress_app1_1, dockerwordpress_mysql_1, dockerwordpress_downloader_1 app1_1 | Check for the wp-config.php app1_1 | Editing wp-config.php... app1_1 | Starting the service ..................
All the Dockerfiles, config files, and scripts are on Github.
Fig is awesome and very easy to use, using fig we can orchestrate building and launching any number of containers using simple instructions.