How to install the latest Docker and Docker Compose on Debian-based Linux systems
In this tutorial, we will install Docker and Docker Compose on Ubuntu. We will first install Docker and then install Docker Compose.
Installing Docker
- Update the apt package index and install aptitude:
sudo apt-get update
sudo apt-get install aptitude
- Install required packages for apt to use HTTPS:
sudo aptitude update
sudo aptitude install \
ca-certificates \
curl \
gnupg
- Add the Docker GPG key to the keyring:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker.gpg
sudo chmod a+r /usr/share/keyrings/docker.gpg
- Add the Docker repository to the apt sources list:
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/usr/share/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
- Update the apt package index again and install Docker:
sudo aptitude update
sudo aptitude install docker-ce docker-ce-cli containerd.io
Adding user to the docker group
- Create the docker group:
sudo groupadd docker
- Add your user to the docker group:
sudo usermod -aG docker $USER
- Activate the changes to groups:
newgrp docker
- Verify that you can run Docker commands without sudo:
docker run hello-world
Installing Docker Compose
- Download the Docker Compose binary:
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
- Apply executable permissions to the binary:
sudo chmod +x /usr/local/bin/docker-compose
- Verify the installation by checking the version of Docker Compose:
docker-compose --version
This should output the version number of the latest Docker Compose.
You have now installed Docker and Docker Compose on Debian-based Linux systems.
Automatic installation
Here's a script that automates the installation of Docker and Docker Compose on Debian-based Linux systems, including adding the current user to the docker group:
Copy the following script into a file, for example, docker-install.sh
, make it executable with chmod +x docker-install.sh
, and then run it with ./docker-install.sh
. This will install Docker and Docker Compose, add the current user to the docker group, and verify the installation of both tools.
#!/bin/bash
# Install Docker and Docker Compose on Debian-based Linux systems
# Include the current user in the docker group
# Install Docker
sudo apt-get update
sudo apt-get install aptitude -y
sudo aptitude update
sudo aptitude install -y \
ca-certificates \
curl \
gnupg
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker.gpg
sudo chmod a+r /usr/share/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo aptitude update
sudo aptitude install -y docker-ce docker-ce-cli containerd.io
# Add the current user to the docker group
sudo groupadd docker
sudo usermod -aG docker $USER
# Install Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" \
-o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
# Verify the installation
docker --version
docker compose --version
Top comments (0)