Today we have a tutorial for you, on how to install Docker Compose on Ubuntu 18.04 VPS.
Docker Compose is used to run multi-container Docker applications. This means that each container will run a standalone application which can also communicate with the other containers present in the same host. Docker Compose uses YAML files to configure all of your Docker containers and configurations. This makes Docker excellent for deploying and testing quickly and easily. Let’s get started with the installation od Docker Compose on Ubuntu 18.04.
Table of Contents
1. Requirements
- For the purposes of this tutorial, we will use an Ubuntu 18.04 VPS.
- Full SSH root access or a user with sudo privileges is also required.
2. Connect via SSH
Connect to your server via SSH as the root user using the following command:
and replace “IP_ADDRESS” and “PORT_NUMBER” with your actual server IP address and SSH port number.
Before starting with the installation you will need to update your system packages to their latest version.
You can do this by running the following command:
Once the upgrade is completed we can move on, to the installation step.
2. Install Docker Compose on Ubuntu 18.04
To get the latest version of Docker Compose, we will install it from the official Docker’s GitHub repository. To install Docker Compose on Ubuntu 18.04, please follow these steps:
First, we will download the Docker Compose with the following command:
Once the download is completed, we will set the permissions for the Compose binary:
We will then verify the installation by checking the Compose version:
The output should be similar to this:
Docker Compose has been installed successfully. Now in the next steps, we will show you some useful Docker Compose commands.
3. Using the Docker Compose Command
In this section, we will show you how to use Docker Compose command to create a container with Docker Compose.
If you want to see the options available to a specific command execute the following command:
If we execute the following command:
The output should be similar to this:
4. Running a Container with Docker Compose
Docker Hub is a public Docker registry in which Docker users can create, test, store, and distribute container images. In this tutorial, we will use a Hello World image for testing purposes.
First, we need to create a directory for the YAML file with the following commands:
Now we need to create the YAML file:
We need to put the following content into the file, then save and close it.
The first line is showing the container name and the second line specifies which image to use.
If you need to look manually at images on your system you can use the following command:
If there are no local images it will show only the headings.
Now we will run the Hello World image by executing the following command:
If there is no local image for Hello World, Docker Compose will pull it from the Docker Hub repository.
After downloading the image, Docker Compose creates a container and runs the hello-world program.
If you want to see the container information, you can use the following command:
The output should be similar to this:
If you need to remove the container for some reason you can run the following command:
Once the container has been removed, we can then remove the image:
In this tutorial, we learned how to install Docker Compose on Ubuntu 18.04, as well as the basics of how to use it.
Of course, you don’t have to install Docker Compose on Ubuntu 18.04 if you use one of our Managed Ubuntu Hosting services, in which case you can simply ask our expert system administrators to install Docker Compose on Ubuntu 18.04 for you. They are available 24×7 and will take care of your request immediately.
PS. If you liked this post on how to install Docker Compose on Ubuntu 18.04, please share it with your friends on the social networks by using the share shortcuts below, or simply leave a comment in the comments section. Thanks.