Docker is an open-source platform that makes easy the process of building, deploying, running, and updating containers. In this tutorial, we’ll explain how to install docker and docker-compose in a fresh Ubuntu 22.04 LTS installation.
Prerequisites
To follow this tutorial, you need to have an Ubuntu 22.04 LTS server with root access.
Installation of Docker
The first step is to update our existing packages list.
sudo apt update
Installation of the prerequisite packages for the installation of Docker
sudo apt install apt-transport-https ca-certificates curl software-properties-common
After installing the prerequisites packages, we need to add the official docker repository GPG key to our system for the safe downloading of Docker.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Let’s add APT sources for the Docker repository
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Let’s make another update
sudo apt update
Now, check if we have added good sources for the docker community edition.
sudo apt-cache policy docker-ce
Voila. We have added the good source list. Let’s install docker in our system.
sudo apt install docker-ce
When the installation finishes, type the following command to view the status of the docker daemon.
Now, Docker is installed and open running in our system.
Installation of docker-compose
Use the following step to install docker-compose. The command we’ll show here will install the last version of docker-compose at the time you are reading this article.
The first step is to retrieve the last release version of docker-compose from his GitHub repository. To do that, use the following command:
VERSION=$(curl --silent https://api.github.com/repos/docker/compose/releases/latest | grep -Po '"tag_name": "\K.*\d')
The version of docker-compose at the time we are writing this article is 2.7.0.
After that, finish the installation by executing the following command:
DESTINATION=/usr/local/bin/docker-compose
sudo curl -L https://github.com/docker/compose/releases/download/${VERSION}/docker-compose-$(uname -s)-$(uname -m) -o $DESTINATION
sudo chmod 755 $DESTINATION
Check the version of your docker-compose:
Conclusion
This article was a quick one with the only purpose to show you how to install Docker and docker-compose on your Ubuntu system. We’ll write a dedicated tutorial to explain Docker and docker-compose themselves. See us in the next tutorial.
I am a Master’s student in computer science passionate about DevOps, Cloud Computing, AI, and BI. I am also a web developer, especially with Django and Laravel Frameworks. I love to share things that work for me with others to save them time searching through the internet to solve the same problem.
2 thoughts on “How to install docker and docker-compose in Ubuntu 22.04”