Linux

Container: Docker Compose on Ubuntu 16.04

What is Docker Compose

Docker Compose is a tool for running multi-container Docker applications. To configure an application’s services with Compose we use a configuration file, and then, executing a single command, it is possible to create and start all the services specified in the configuration.

Docker Compose is useful for many different projects like:

  • Development: with the Compose command line tools we create (and interact with) an isolated environment which will host the application being developed.
    By using the Compose file, developers document and configure all of the application’s service dependencies.
  • Automated testing: this use case requires an environment for running tests in. Compose provides a convenient way to manage isolated testing environments for a test suite. The full environment is defined in the Compose file.

Docker Compose was made on the Fig source code, a community project now unused.

In this tutorial we will see how to install Docker Compose on an Ubuntu 16.04 machine.

Install Docker

We need Docker in order to install Docker Compose. First, add the public key for the official Docker repository:

Next, add the Docker repository to apt sources list:

Update the packages database and install Docker with apt:

At the end of the installation process, the Docker daemon should be started and enabled to load at boot time. We can check its status with the following command:

Active: active (running)

Install Docker Compose

At this point it is possible to install Docker Compose. Download the current release by executing the following command:

Make the downloaded binary executable:

Check the Docker Compose version:

The output should be something like this:

Testing Docker Compose

The Docker Hub includes a Hello World image for demonstration purposes, illustrating the configuration required to run a container with Docker Compose.

Create a new directory and move into it:

Create a new YAML file:

In this file paste the following content:

Note: the first line is used as part of the container name.

Save and exit.

Run the container

Next, execute the following command in the hello-world directory:

If everything is correct, this should be the output shown by Compose:

Docker containers only run as long as the command is active, so the container will stop when the test finishes running.

Show More

Related Articles

Leave a Reply

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

Close