This guide explains how to install Docker and Docker Compose on Ubuntu 20.04. While docker-compose may not come installed on ubuntu 20.04, the OS does come with Docker. This means you’re just a few simple steps away from unlocking the full potential of container orchestration by just installing docker-compose. So, without further ado, let’s dive in and discover the power of Docker Compose on Ubuntu 20,04.
What is needed?
- Computer with Ubuntu 20.04 installed, A Virtual Machine with Ubuntu 20.04 Installed, or a Cloud VPS Account (See my Guide on how to set up a Cloud Hosting Account)
- Basic Linux Foundations (Optional)
Docker Video Guide
What’s in this section?
- Installing Docker on Ubuntu Linux 20.04 and 20.10
- Introduction to Docker and Docker Compose
- What is the difference between Dockerfile and Docker Compose?
- Is Docker-Compose Deprecated?
- Docker, Docker-compose, and Docker Compose – A love triangle
- Does Ubuntu Linux 20.04 and 20.10 come with Docker Installed?
Next Article: Installing Portainer Using Docker Compose
Installing Docker on Ubuntu 20.04
Before we begin, it’s important to check if the essential building block – Docker – is already installed on your machine.
1. How to Check if Docker is Installed on Ubuntu 20.04
With the simple command below, you can easily verify the presence of Docker and even check the version that’s currently running.
docker –version
2. Update the Ubuntu 20.04 OS
If Docker isn’t currently installed on your Ubuntu machine. The first step in getting Docker up and running on your system is to ensure that your package list is up-to-date by running the simple command shown below. This will ensure that you have the latest version of Docker and all its dependencies ready to go.
sudo apt update
3. Install Packages needed for Docker to run on Ubuntu 20.04
With your package list now updated, the next step is to install the necessary packages that will allow you to add the Docker repository to your system. This will give you access to the latest version of Docker and all its dependencies, ensuring that you have a smooth and efficient containerized experience. So, run the command below to get those packages installed, as one step closer to a fully-functional Docker setup on Ubuntu Linux.
sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
4. Add the Official GPG Key to the OS
We’re making progress! With the necessary packages now installed, the next step is to add the official Docker GPG key to your system. This is an important step as it will ensure that the packages you’re downloading are authentic with no tampering evidence. By running this simple command. You will be taking a crucial step toward a secure and stable Docker setup on your Ubuntu Linux machine. So, let’s add that key and keep moving forward toward a fully-functional containerized environment.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
5. Add Docker Repository to the System
It’s now time to take the next step which involves adding the Docker repository to your system. By running the command below. You will be able to access the latest version of Docker and all its dependencies, ensuring that your containerized applications run smoothly and efficiently. So, let’s add the repository!
sudo add-apt-repository “deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable”
6. Update the Package Again
We’re in the final stretch! With the Docker repository now added to your system. The next step is to update the package list one more time. This will ensure that you have access to the latest version of Docker and all its dependencies and that your system is aware of them. By running this simple command, you’ll be taking the last step towards a stable and efficient containerized experience on Ubuntu Linux. So, let’s update the package list and get ready to start running those containerized applications with ease.
sudo apt update
7. Get Docker Running on your Ubuntu 20.04
We’ve made it to the end of the journey! The last step in getting Docker up and running on your Ubuntu Linux machine is to install the latest version of Docker itself. By running this command, you’ll be able to start using Docker to run your containerized applications with ease. So, let’s go ahead and install the latest version of Docker and get ready to experience the power of containerization on Ubuntu Linux.
sudo apt install docker-ce
8. Installation Completed: Test if Docker is running
Congratulations, you’ve successfully installed Docker on your Ubuntu Linux machine! The final step to ensure that everything is running smoothly is to verify that Docker is indeed up and running. By running this simple command, you’ll be able to confirm that Docker is functioning properly and that you’re ready to start using it to run your containerized applications. So, let’s go ahead and run the command and make sure that Docker is up and running on your Ubuntu Linux machine.
sudo systemctl status docker
9. Change your account to Root User
With Docker successfully installed and running on your Ubuntu Linux machine, you’re now ready to start using it to run your containerized applications. However, to avoid having to use sudo every time you run a Docker command, you’ll need to add your user to the docker group. By running this command, you’ll be able to execute Docker commands as your regular user, making the process more seamless and efficient. So, let’s go ahead and add your user to the docker group and get ready to fully experience the power of containerization on Ubuntu Linux.
sudo usermod -aG docker $USER.
Installing Docker Compose on Ubuntu 20.04
Now that you have docker installed, let now install Docker Compose.
1. Update the System (Ubuntu Linux 20.04)
First, you need to open a terminal window and update the package list yet again. By now you know how to do it:
sudo apt update
2. Install the Packages needed by Docker Compose
Great, now that our package list is up to date, it’s time to install the required packages for Docker Compose. In the terminal, run the command below. This command installs python3-pip package that is needed to run the installation process. It’s as easy as that! With just one command we’re one step closer to having Docker Compose up and running on our Ubuntu machine.
sudo apt install -y python3-pip
3. Download the latest version of Docker Compose using Pip3
We’re making progress! Now it’s time to download the latest version of Docker Compose using pip3 package installer. Running the command below will install the latest version of Docker Compose using pip3. It will download the package from PyPi (Python Package Index) and install it to your system. Additionally, it will also automatically handle any dependencies that Docker Compose needs.
pip3 install docker-compose
4. Verify the Installation
Now that we have Docker Compose installed, let’s verify the installation. We ran this command when we were checking the docker version and docker installation. It basically displays the version number of the installed Docker Compose where you can check if it’s the latest version or not. If the installation was successful, you should see the version number of Docker Compose displayed in the terminal. This is a quick and easy way to confirm that the installation was successful and that you can start using Docker Compose on your Linux Ubuntu machine.
docker-compose –version
5. Make the Docker Compose Script Executable
Once you have verified that Docker Compose is installed, you can start using it to manage your containers. Note: You should always make sure to use the latest version of Docker Compose to ensure that you have the latest features and bug fixes. Also, you may want to run the command below to make sure that the script is executable, otherwise, the command “docker-compose –version ” will output the error “Command not found”.
The command uses the chmod command to add execute permissions for the owner, group, and others for the binary file of Docker Compose, located in the /usr/local/bin directory. This step is necessary to be able to run the Docker Compose command from anywhere on your system without specifying the full path to the binary file. After running this command, you’ve successfully installed and set up Docker Compose on your Ubuntu 20.04 machine and you can start using all the functionalities provided by it.
sudo chmod +x /usr/local/bin/docker-compose
Understanding Docker and Docker-Compose
Docker has revolutionized the way we deploy and run applications by introducing the concept of containerization. By using docker, developers can package their applications in a lightweight, portable format that can run consistently across different environments. However, managing multiple containers can be a daunting task, especially as the number of containers grows. This is where Docker-compose comes in.
What is Docker Compose?
Docker-compose is a tool that makes it easy to manage and orchestrate multiple containers by defining them in a single file called a docker-compose.yml. This allows developers to define their services, dependencies, and how they should be connected and interacted with. With the help of Docker-compose, developers can easily create, start, stop, and scale their applications, making the containerization process more manageable and efficient.
It’s like having a blueprint for your application, where you can specify the containers you need, their configurations, and how they interact with each other. With Docker-compose, you can easily spin up and tear down your entire application with just a few commands. But it doesn’t stop there. Docker-compose also allows you to manage and scale your containerized application and allows for easy networking between containers.
The difference between Dockerfile and Docker compose
A Dockerfile is a script that contains instructions on how to build a container image. It’s like a recipe that tells the computer what ingredients to use and how to put them together to create a container. It’s mainly used to create a custom image for an application.
In simpler words, think of a Dockerfile as the instructions to make a cake and Docker Compose as the instructions to make a whole cake shop with different types of cakes, where each cake is a container.
Docker Compose with and without a Hyphen
With the release of Docker 19.03, the docker compose command without a hyphen between the words docker and compose was introduced. The command works the same way as the traditional docker-compose command that has a hyphen, and it’s available on Docker for Windows and Mac. This command allows you to use docker compose command without a hyphen instead of the conventional way in which you had to put a hypen between the words docker and compose to run the compose file.
Is Docker-compose deprecated?
On Linux, the new docker compose command is not supported by default, but there is a community-contributed package called docker-compose-plugin that you can install on your Linux distribution. This package adds an alias for the docker-compose command to the docker command so that you can use the docker-compose command instead of the docker-compose command to run the compose file.
As you can see, the docker-compose command is not deprecated, instead, a different variation of the command was introduced by the docker community.
Docker vs Docker-Compose vs Docker Compose
So, what’s the difference between the three? The difference is as follows. Docker is the tool that allows you to containerize your application. Docker-compose is a tool that allows you to define and run multi-container applications, and manage and scale them. Docker Compose is a shorthand for the docker-compose command that is only available on Windows and Mac. It’s like a love triangle where each tool is special in its own way, and they all work together to make containerization a breeze.
As we have seen, Docker, Docker-compose, and Docker Compose are all important tools for containerization. Each one of them has its own unique features and advantages. Understanding the difference between these tools and knowing how to use them can help you take your containerization skills to the next level. This will make your work more efficient and streamlined.
Does Ubuntu Linux 20.04 and 20.10 come with docker pre-installed?
Ubuntu is a popular open-source operating system that is widely used for both personal and professional use. Ubuntu 20.04 does not come with Docker Compose pre-installed. However, it does come with Docker installed. To install Docker Compose on Ubuntu 20.04, you would need to follow the aforelisted installation steps. These are the same instructions provided by the Docker Compose project.
The latest version Ubuntu 20.10 brings a lot of new features and improvements. One of the major features of this version is the updated kernel version which provides better performance and a more stable system.
Is Ubuntu the best Linux distro for Docker Containers
One of the most exciting things about Ubuntu is that it is designed to work seamlessly with technologies like Docker and Docker Compose. Docker and Docker Compose make it easy to create, deploy, and manage applications on Ubuntu.
Whether you’re a developer looking to create a new application or an IT professional looking to manage a fleet of servers. Ubuntu’s support for these technologies makes it a great choice. The combination of Ubuntu, Docker, and Docker Compose makes it a powerful and flexible platform for developing, testing, and deploying applications in a consistent and efficient way.