Docker Compose to Orchestrate Containers – Tech Tip #77

Docker Orchestration using Fig showed how to defining and control a multi-container service using Fig. Since then, Fig has been renamed to Docker Compose, or Compose for short.

First release of Compose was announced recently

From github.com/docker/compose

Compose is a tool for defining and running complex applications with Docker. With Compose, you define a multi-container application in a single file, then spin your application up in a single command which does everything that needs to be done to get it running.

Docker Compose uses the same API used by other Docker commands and tools.

Docker Compose

This Tech Tip will rewrite Docker Orchestration using Fig blog to use Docker Compose. In other words, it will show how to run a Java EE 7 application that is deployed using MySQL and WildFly.

Lets get started!

Install Docker Compose

Install Compose as:

Docker Compose Configuration File

Entry point to Compose is docker-compose.yml. To begin with, docker-compose tool also recognizes fig.yml file name but shows the following message:

And if both fig.yml and docker-compose.yml are available in the directory then the following message is shown:

Use the same configuration file from the previous blog and rename to docker-compose.yml:

This YML-based configuration file has:

  1. Two containers defined by the name “mysqldb” and “mywildfly”
  2. Image names are defined using “image”
  3. Environment variables for the MySQL container are defined in “environment”
  4. MySQL container is linked with WildFly container using “links”
  5. Port forwarding is achieved using “ports”

Start, Verify, Stop Docker Containers

  1. All the containers can be started, in detached mode, by giving the command:
    And that shows the output as:
  2. Verify the containers as:
  3. Logs for the containers can be seen as:
    And shows the output as:
  4. Find the IP address of the host as:
    And access the application as:
    To see the output as:
    Or in the browser as:

    Docker Compose Output

  5. Stop the containers as:

    to see the output as:

Docker Compose Commands

Complete list of Docker Compose commands can be seen by typing docker-compose and shows the output as:

A subsequent blog will likely play with scale command.

Help for each command is shown by typing -h after the command name. For example, help for run command is shown as:

Enjoy!

Be Sociable, Share!

15 thoughts on “Docker Compose to Orchestrate Containers – Tech Tip #77

  1. Question.. How do i use cid=$(ifconfig eth0 | grep ‘inet addr:’ | cut -d: -f2…) inside a docker-compose.yml file?

  2. i get troubleshooting in running [root@ix1-dv-c6-survey-01 javaee7-arungupta]# docker run arungupta/wildfly-mysql-javaee7
    /bin/bash: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: Permission denied.
    I am on centOS 6.7, SELinux disabled (https://github.com/docker/docker/issues/7318)
    uname -a
    Linux 020e23a319a9 2.6.32-573.3.1.el6.x86_64 #1 SMP Thu Aug 13 22:55:16 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
    mount | grep ‘ / ‘
    /dev/mapper/VG0-lv_root on / type ext4 (rw)
    [root@ix1-dv-c6-survey-01 javaee7-arungupta]# docker version
    Client version: 1.7.1
    Client API version: 1.19
    Go version (client): go1.4.2
    Git commit (client): 786b29d
    OS/Arch (client): linux/amd64
    Server version: 1.7.1
    Server API version: 1.19
    Go version (server): go1.4.2
    Git commit (server): 786b29d
    OS/Arch (server): linux/amd64

Leave a Reply

Your email address will not be published. Required fields are marked *