On our previous article we saw how to install docker on Ubuntu 17.04. That is suitable for running a individual container(single applications). What if we want to run multi container application?

    This leads to the invention of docker-compose, In this article, we will see you how to install the latest version of Docker Compose to help you to manage multi-container applications.

Installing Docker Compose:

    Run the below curl command which will download and install the latest version of docker-compose,

jhony@ljunix~$ sudo curl -L https://github.com/docker/compose/releases/
download/1.18.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose


Change the permission of the downloaded file which will make it as an executable one,

jhony@ljunix~$ sudo chmod +x /usr/local/bin/docker-compose


Check your installation:

    Run the below command to check the version of docker-compose,

jhony@ljunix~$ docker-compose --version
docker-compose version 1.18.0, build 8dd22a9


Verify your installation:

    We can check whether the installation is successful or not by running the docker-compose command,

Running a Container with Docker Compose:

    Docker compose will always check for for a YAML file called as docker-compose.yml. To check our installation we will create a directory called hello-world where we going to run the hello-world image.

jhony@ljunix~$ mkdir hello-world

jhony@ljunix~$ cd hello-world


    Create the YAML file for the hello-world image with you favourite text editor,

jhony@ljunix:hello-world/$ vim docker-compose.yml


Paste the below content into docker-compose.yml file,

my-test:
image: hello-world


The first line in the YAML file is used as part of the container name. The second line specifies which image to use to create the container. Likewise we can add more containers with above syntax.

Now run the docker-compose command to run the application,

jhony@ljunix:hello-world/$ docker-compose up
Pulling my-test (hello-world:latest)...
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:2557e3c07ed1e38f26e389462d03ed94
3586f744621577a99efb77324b0fe535
Status: Downloaded newer image for hello-world:latest
Creating tmp_my-test_1 ... done
Attaching to tmp_my-test_1
my-test_1 |
my-test_1 | Hello from Docker!
my-test_1 | This message shows that your installation appears to be working correctly.
my-test_1 |
my-test_1 | To generate this message, Docker took the following steps:
my-test_1 | 1. The Docker client contacted the Docker daemon.
my-test_1 | 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
my-test_1 | (amd64)
my-test_1 | 3. The Docker daemon created a new container from that image which runs the
my-test_1 | executable that produces the output you are currently reading.
my-test_1 | 4. The Docker daemon streamed that output to the Docker client, which sent it
my-test_1 | to your terminal.
my-test_1 |
my-test_1 | To try something more ambitious, you can run an Ubuntu container with:
my-test_1 | $ docker run -it ubuntu bash
my-test_1 |
my-test_1 | Share images, automate workflows, and more with a free Docker ID:
my-test_1 | https://hub.docker.com/
my-test_1 |
my-test_1 | For more examples and ideas, visit:
my-test_1 | https://docs.docker.com/get-started/
my-test_1 |
tmp_my-test_1 exited with code 0


    If your installation is successful you will get the above output.

 We've now successfully installed Docker Compose in our system.

Feel free to ask if you have any questions.

Comments

  1. Be the first to add a comment.