Installing Docker and Docker Compose on Ubuntu
Docker has become standard infrastructure for modern development and deployment, ensuring environment consistency and rapid delivery. However, inconsistent installation methods and version management remain common. This guide provides a standardized Docker and Docker Compose installation process on Ubuntu for a stable, reproducible, and maintainable environment.
Introduction
Docker has become standard infrastructure for modern development and deployment, used to achieve environment consistency and rapid delivery.
However, in practical use, issues such as chaotic installation methods, inconsistent versions, and non-standard Compose management remain common.
This article will provide a standardized Docker and Docker Compose installation process from scratch, ensuring the environment is stable, reproducible, and maintainable.
Prepare Environment
Update Ubuntu
sudo apt update && sudo apt upgrade -y
Add Docker Repository
sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg lsb-release
Add Docker’s Official GPG Key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Add Docker Official 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
Update Ubuntu Source List
sudo apt update
Install Latest Docker
sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin
Run Docker Service
sudo systemctl start docker
Configure Docker to Start on Boot
sudo systemctl enable docker
Verify if Docker Service is Running
sudo systemctl status docker
Check Installed Docker Version
sudo docker version
Install Docker Compose
Method 1
Install Docker Compose using binary file.
Download Latest Docker Compose
https://github.com/docker/compose/releases
Install Latest Stable Docker Compose File
When writing this article, the latest version is v2.40.3.
If there is a newer version, simply replace v2.40.3 in the command above with the latest version number. Please do not forget the “v” before the number.
sudo curl -L "https://github.com/docker/compose/releases/download/v2.40.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
Finally, Grant Execute Permission to the Binary File
sudo chmod +x /usr/local/bin/docker-compose
Check Installed Docker Compose Version
sudo docker-compose version
Method 2
Install Docker Compose using pip
Refer to my previous link for pip installation
After installing pip, run the following command to install Docker Compose.
pip install docker-compose
Check Docker Compose Version
docker-compose --version
Previous
Installing Python and Pip on Ubuntu