Install Docker Compose On Linux

  • Docker Tutorial
  • Docker Useful Resources

Install Docker and Compose into Ubuntu 18.04 Just one command: snap install docker email protected:# snap install docker docker 18.09.9 from Canonical installed It will also install docker-compose. If your Ubuntu 18.04 notifies you do not have snap, you can install it with following command: apt install snap. Install Docker Compose Ec2 Linux Command Customize and share multi-service applications and service templates that are tailored to your organization. Pre-defined and customizable application templates adhere to corporate standards and automate configuration, eliminating error-prone manual setup. The recommended method for installing Docker Compose on CentOS 7 is by downloading the Compose binary from the Docker’s GitHub repository. At the time of writing this article, the latest stable version of Docker Compose is version 1.23.1.

  • Selected Reading

To start the installation of Docker, we are going to use an Ubuntu instance. You can use Oracle Virtual Box to setup a virtual Linux instance, in case you don’t have it already.

The following screenshot shows a simple Ubuntu server which has been installed on Oracle Virtual Box. There is an OS user named demo which has been defined on the system having entire root access to the sever.

To install Docker, we need to follow the steps given below.

Step 1 − Before installing Docker, you first have to ensure that you have the right Linux kernel version running. Docker is only designed to run on Linux kernel version 3.8 and higher. We can do this by running the following command.

uname

This method returns the system information about the Linux system.

Syntax

Options

a − This is used to ensure that the system information is returned.

Return Value

This method returns the following information on the Linux system −

  • kernel name
  • node name
  • kernel release
  • kernel version
  • machine
  • processor
  • hardware platform
  • operating system

Example

Output

When we run above command, we will get the following result −

From the output, we can see that the Linux kernel version is 4.2.0-27 which is higher than version 3.8, so we are good to go.

Step 2 − You need to update the OS with the latest packages, which can be done via the following command −

This method installs packages from the Internet on to the Linux system.

Syntax

sudo apt-get update

Options

  • sudo − The sudo command is used to ensure that the command runs with root access.

  • update − The update option is used ensure that all packages are updated on the Linux system.

Install

Return Value

None

Example

Output

When we run the above command, we will get the following result −

This command will connect to the internet and download the latest system packages for Ubuntu.

Step 3 − The next step is to install the necessary certificates that will be required to work with the Docker site later on to download the necessary Docker packages. It can be done with the following command.

Step 4 − The next step is to add the new GPG key. This key is required to ensure that all data is encrypted when downloading the necessary packages for Docker.

The following command will download the key with the ID 58118E89F3A912897C070ADBF76221572C52609D from the keyserver hkp://ha.pool.sks-keyservers.net:80 and adds it to the adv keychain. Please note that this particular key is required to download the necessary Docker packages.

Step 5 − Next, depending on the version of Ubuntu you have, you will need to add the relevant site to the docker.list for the apt package manager, so that it will be able to detect the Docker packages from the Docker site and download them accordingly.

  • Precise 12.04 (LTS) ─ deb https://apt.dockerproject.org/repoubuntu-precise main

  • Trusty 14.04 (LTS) ─ deb https://apt.dockerproject.org/repo/ ubuntu-trusty main

  • Wily 15.10 ─ deb https://apt.dockerproject.org/repo ubuntu-wily main

  • Xenial 16.04 (LTS) - https://apt.dockerproject.org/repo ubuntu-xenial main

Since our OS is Ubuntu 14.04, we will use the Repository name as “deb https://apt.dockerproject.org/repoubuntu-trusty main”.

And then, we will need to add this repository to the docker.list as mentioned above.

Step 6 − Next, we issue the apt-get update command to update the packages on the Ubuntu system.

Step 7 − If you want to verify that the package manager is pointing to the right repository, you can do it by issuing the apt-cache command.

In the output, you will get the link to https://apt.dockerproject.org/repo/

Step 8 − Issue the apt-get update command to ensure all the packages on the local system are up to date.

Step 9 − For Ubuntu Trusty, Wily, and Xenial, we have to install the linux-image-extra-* kernel packages, which allows one to use the aufs storage driver. This driver is used by the newer versions of Docker.

It can be done by using the following command.

Step 10 − The final step is to install Docker and we can do this with the following command −

Here, apt-get uses the install option to download the Docker-engine image from the Docker website and get Docker installed.

The Docker-engine is the official package from the Docker Corporation for Ubuntu-based systems.

In the next section, we will see how to check for the version of Docker that was installed.

Docker Version

To see the version of Docker running, you can issue the following command −

Syntax

Options

  • version − It is used to ensure the Docker command returns the Docker version installed.

Return Value

The output will provide the various details of the Docker version installed on the system.

Example

Output

When we run the above program, we will get the following result −

Docker Info

To see more information on the Docker running on the system, you can issue the following command −

Syntax

Options

  • info − It is used to ensure that the Docker command returns the detailed information on the Docker service installed.

Return Value

The output will provide the various details of the Docker installed on the system such as −

  • Number of containers
  • Number of images
  • The storage driver used by Docker
  • The root directory used by Docker
  • The execution driver used by Docker

Example

Output

When we run the above command, we will get the following result −

Docker for Windows

Docker has out-of-the-box support for Windows, but you need to have the following configuration in order to install Docker for Windows.

System Requirements

Windows OSWindows 10 64 bit
Memory2 GB RAM (recommended)

You can download Docker for Windows from − https://docs.docker.com/docker-for-windows/

Docker ToolBox

Docker ToolBox has been designed for older versions of Windows, such as Windows 8.1 and Windows 7. You need to have the following configuration in order to install Docker for Windows.

System Requirements

Windows OSWindows 7 , 8, 8.1
Memory2 GB RAM (recommended)
VirtualizationThis should be enabled.

You can download Docker ToolBox from − https://www.docker.com/products/docker-toolbox


Tutorial

Introduction

Docker is a great tool for automating the deployment of Linux applications inside software containers, but to take full advantage of its potential each component of an application should run in its own individual container. For complex applications with a lot of components, orchestrating all the containers to start up, communicate, and shut down together can quickly become unwieldy.

The Docker community came up with a popular solution called Fig, which allowed you to use a single YAML file to orchestrate all your Docker containers and configurations. This became so popular that the Docker team decided to make Docker Compose based on the Fig source, which is now deprecated. Docker Compose makes it easier for users to orchestrate the processes of Docker containers, including starting up, shutting down, and setting up intra-container linking and volumes.

In this tutorial, we’ll show you how to install the latest version of Docker Compose to help you manage multi-container applications.

Prerequisites

To follow this article, you will need an Ubuntu 18.04 server with the following:

  • A non-root user with sudo privileges (Initial Server Setup with Ubuntu 18.04 explains how to set this up.)
  • Docker installed with the instructions from Step 1 and Step 2 of How To Install and Use Docker on Ubuntu 18.04

Docker Compose Ubuntu

Once these are in place, you’re ready to follow along.

Note: Even though the Prerequisites give instructions for installing Docker on Ubuntu 18.04, the docker commands in this article should work on other operating systems as long as Docker is installed.

Step 1 — Installing Docker Compose

Install Docker Compose On Ec2 Linux

Although we can install Docker Compose from the official Ubuntu repositories, it is several minor version behind the latest release, so we’ll install Docker Compose from the Docker’s GitHub repository. The command below is slightly different than the one you’ll find on the Releases page. By using the -o flag to specify the output file first rather than redirecting the output, this syntax avoids running into a permission denied error caused when using sudo.

We’ll check the current release and if necessary, update it in the command below:

Next we’ll set the permissions:

Then we’ll verify that the installation was successful by checking the version:

This will print out the version we installed:

Now that we have Docker Compose installed, we’re ready to run a “Hello World” example.

Step 2 — Running a Container with Docker Compose

The public Docker registry, Docker Hub, includes a Hello World image for demonstration and testing. It illustrates the minimal configuration required to run a container using Docker Compose: a YAML file that calls a single image:

First, we’ll create a directory for the YAML file and move into it:

Then, we’ll create the YAML file:

Put the following contents into the file, save the file, and exit the text editor:

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. When we run the command docker-compose up it will look for a local image by the name we specified, hello-world. With this in place, we’ll save and exit the file.

We can look manually at images on our system with the docker images command:

When there are no local images at all, only the column headings display:

Now, while still in the ~/hello-world directory, we’ll execute the following command:

Docker Compose Releases

The first time we run the command, if there’s no local image named hello-world, Docker Compose will pull it from the Docker Hub public repository:

After pulling the image, docker-compose creates a container, attaches, and runs the hello program, which in turn confirms that the installation appears to be working:

Then it prints an explanation of what it did:

Docker containers only run as long as the command is active, so once hello finished running, the container stopped. Consequently, when we look at active processes, the column headers will appear, but the hello-world container won’t be listed because it’s not running.

Install Docker-compose On Arch Linux

We can see the container information, which we’ll need in the next step, by using the -a flag which shows all containers, not just the active ones:

This displays the information we’ll need to remove the container when we’re done with it.

Step 3 — Removing the Image (Optional)

To avoid using unnecessary disk space, we’ll remove the local image. To do so, we’ll need to delete all the containers that reference the image using the docker rm command, followed by either the CONTAINER ID or the NAME. Below, we’re using the CONTAINER ID from the docker ps -a command we just ran. Be sure to substitute the ID of your container:

Once all containers that reference the image have been removed, we can remove the image:

Install Docker Compose Ec2

Conclusion

Install Docker Compose In Linux Ubuntu

We’ve now installed Docker Compose, tested our installation by running a Hello World example, and removed the test image and container.

While the Hello World example confirmed our installation, the simple configuration does not show one of the main benefits of Docker Compose — being able to bring a group of Docker containers up and down all at the same time. To see the power of Docker Compose in action, you might like to check out this practical example, How To Configure a Continuous Integration Testing Environment with Docker and Docker Compose on Ubuntu 16.04(note: this article is for Ubuntu 16.04 rather than 18.04)