This article was contributed by Dustin B. Cisneros of RackNerd – LowEndBox appreciates your contribution as always! Looking for a KVM VPS to run your Docker applications on? Be sure to check out RackNerd’s latest LowEndBox specials if you are looking for a KVM VPS.
Docker Compose is an extremely useful tool that allows you to run multi-container Docker applications on a single host. The Docker Compose can be used be in all stages of an application including the production, development, and the testing.
Docker Compose is a command-line tool and requires a Dockerfile to define the environment for the application. Moreover, the services can be defined in a “docker-compose.yml” file.
If you are looking for a tool to run multiple isolated environments, Docker Compose is the industry standard and an excellent choice.
In this guide, we will instruct you on how you can install, and setup Docker Compose on your machine running Ubuntu 20.04.
Step 1. Prerequisites
Before we start, make sure that you Docker installed on your system. Moreover, you would need root access to the machine to continue.
Step 2. Download the binary file
Docker Compose is available on GitHub as a binary file. At the time of writing this, the latest available version is 1.26.0. We will use “Curl” to download the file off of GitHub.
Use the following command to download the file:
‘sudo curl -L “https://github.com/docker/compose/releases/download/1.26.0/docker-compose-$(uname -s)-$(uname -m)” -o /usr/local/bin/docker-compose’
However, you can check for the latest version at Docker Compose GitHub page and substitute the “1.26.0” with the newest version.
Step 3. Apply appropriate permissions
Once, the download is complete; we need to apply the executable permission to Docker Compose. Do that with the following command:
“sudo chmod +x /usr/local/bin/docker-compose”
Step 4. Verify installation
Now, Docker Compose should be installed on your machine. To verify the installation, run the following command:
If the installation is successful, the output would display the version and build information for Docker Compose.
Now, Docker Compose is up and running on your Ubuntu 20.04 machine. Let’s see how to set it up.
We will go through a mock WordPress application for you to get started with Docker Compose.
Step 1. Make a project directory
Run the following commands:
“mkdir compose_project && cd compose_project”
Step 2. Create the YML file
Now to set up the environment for our application, we need to create a “docker-compose.yml” file. You can do that with the following command:
Step 3. Set up the YML file
Paste the following into the .YML file:
This file will set up the environment for your application. In this file, we define the required services, such as WordPress and a database. All the services run in a separate container.
Step 4. Start the application
Now, that we have set up our services, we can start our application by running the following command:
This will pull all the required services and start the application at on port 8080 within your server’s network.
You can stop the Docker Compose application by pressing “CTRL + C”.
Other useful Compose commands include:
– “docker-compose ps” = To check which services are running.
– “docker-compose up -d” = To start the application in detached mode.
– “docker-compose stop” = To stop application applications in detached mode.
Have you set up a Docker environment on Ubuntu 20.04 yet? Share your tips and tricks in the comments section below!