Skip to content

Docker - Installing Docker on Linux

This section provides detailed steps for installing Docker Engine on a Linux system, focusing on the recommended method using Docker’s official repositories. This ensures you get the latest stable version and updates.

We’ll use Ubuntu as the primary example, but the general process is similar for other supported distributions (Debian, Fedora, CentOS) – consult the official Docker documentation for distribution-specific commands.

  • A supported version of a Linux distribution (e.g., Ubuntu 22.04, 20.04).
  • 64-bit architecture.
  • Sudo privileges for your user account.
  • Internet access to download packages.

Docker requires a Linux kernel version 3.10 or higher. Most modern distributions meet this requirement. You can check your version using:

uname -r

Output will show the kernel release, e.g., 5.15.0-87-generic.

Step 1: Uninstall Old Versions (If applicable)

If you have older versions of Docker installed (e.g., docker, docker-engine, docker.io), uninstall them first:

sudo apt-get remove docker docker-engine docker.io containerd runc

It’s okay if apt-get reports that none of these packages are installed.

Step 2: Set up the Repository

a. Update the apt package index and install packages to allow apt to use a repository over HTTPS:

sudo apt-get update
sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release

b. Add Docker’s official GPG key:

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

c. Use the following command to set up the stable repository:

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

Step 3: Install Docker Engine

a. Update the apt package index again:

sudo apt-get update

b. Install Docker Engine, CLI, containerd, and Docker Compose plugin (latest versions):

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

(docker-ce is the engine, docker-ce-cli is the command line client, containerd.io is the container runtime, docker-compose-plugin provides docker compose command).

Step 4: Verify Installation

Verify that the Docker Engine installation is successful by running the hello-world image:

sudo docker run hello-world

This command downloads a test image and runs it in a container. A successful run will print a confirmation message.

Post-installation Steps (Manage Docker as a non-root user)

Section titled “Post-installation Steps (Manage Docker as a non-root user)”

By default, the Docker daemon binds to a Unix socket owned by the root user. To run Docker commands without prefixing them with sudo, you need to add your user to the docker group (which is created during installation).

Step 5: Add your user to the docker group:

sudo usermod -aG docker $USER

Step 6: Apply the group changes.

You need to log out and log back in for your new group membership to be activated. Alternatively, you can activate the changes for your current session using:

newgrp docker

After this, you should be able to run Docker commands without sudo.

docker run hello-world

To see detailed version information:

docker version

To see system-wide information, including the number of containers/images, storage driver, logging driver, etc.:

docker info