Published on

How to install Docker and Docker Compose on Ubuntu (In 10 steps)

Authors

1. Update the package list and upgrade installed packages

The first step ensures that your package list is up to date, and any outdated packages on your system are upgraded.

sudo apt update
sudo apt upgrade -y

2. Install required packages for Docker

Next, you’ll install the necessary packages to add Docker’s GPG key and repository.

sudo apt install -y ca-certificates curl gnupg lsb-release

3. Add Docker’s GPG key

This step downloads Docker’s GPG key and saves it in a secure location, allowing your system to verify Docker packages.

sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

4. Add Docker's official repository

Add Docker's stable repository to your system so that you can install Docker and its components directly from Docker’s official repository.

sudo echo  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update

5. Install Docker Engine and Docker Compose Plugin

Now you’ll install Docker Engine, the Docker CLI, containerd, and Docker Compose plugin with this single command.

sudo apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin

6. Verify Docker installation

Run a test container to ensure Docker is installed correctly.

sudo docker run hello-world

7. Add Docker group

This step creates a Docker group so that Docker can be run without sudo.

sudo groupadd docker

8. Add your user to the Docker group

Add your user to the Docker group to avoid using sudo for Docker commands.

sudo usermod -aG docker $USER

9. Install Docker Compose

Download the latest version of Docker Compose and give it executable permissions.

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

10. Verify Docker Compose installation

Finally, verify that Docker Compose is successfully installed by checking its version.

docker-compose --version

By following these steps, you'll have Docker and Docker Compose installed on your Ubuntu system, ready for containerized applications.