instalar-docker-linux

Install Docker on Linux

  • 4 min

If you are a Linux user, you are playing at home. Docker is native Linux technology. Unlike Windows or Mac, there are no intermediate virtual machines or system call translations here.

Here, Docker talks directly with the Kernel. That’s why performance on Linux is unbeatable. However… not everything is perfect.

If you open your terminal and simply type sudo apt install docker.io, you will most likely install an old, outdated version maintained by your distribution, not by Docker.

In this article, we will see how to install the latest version of Docker Community Edition (CE) using the official repositories, and how to configure it properly.

This guide focuses on Ubuntu and Debian (and derivatives). If you use Fedora, CentOS, or Arch, the steps are similar but the package managers (dnf or pacman) differ.

Pre-cleanup

Before anything else, if you ever tried to install Docker and it failed, or you have an old version, let’s clean the system to avoid conflicts.

Open your terminal and run:

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

Don’t worry if it says there was nothing installed. Better safe than sorry.

Prepare the official repository

To always have the latest version, we will tell your Linux to trust the official Docker repository.

Update the package index and install dependencies so that apt can use HTTPS repositories:

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

Add the official Docker GPG key. This allows your system to verify that what you download is secure and actually comes from Docker Inc:

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

Add the repository to your sources list:

echo
“deb [arch=(lsb_release -cs) stable” | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

If you use a derivative distro (like Linux Mint), sometimes $(lsb_release -cs) returns the Mint version name instead of the Ubuntu version it is based on.

If it fails, you will have to manually enter the Ubuntu codename (e.g., jammy, focal).

Install Docker Engine

Now we have the official repository configured. Now let’s install Docker Engine:

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

Notice that we have installed several packages:

  • docker-ce: The Docker engine (the Daemon).
  • docker-ce-cli: The client (the commands).
  • containerd.io: The container runtime.
  • docker-compose-plugin: Installs Docker Compose.

The sudo problem

If you now try to run docker run hello-world, you will see this:

docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock…

This happens because the Docker Daemon runs as root, and for security reasons, only root can communicate with it. But it’s a huge pain to have to use sudo for everything.

To fix this, Docker creates a user group called docker. Anyone belonging to this group has permission to communicate with the Daemon.

So let’s add your current user to that group:

sudo usermod -aG docker $USER

This change does not take effect immediately. For your system to recognize that you have changed groups, you need to log out and log back in, or restart your computer.

If you don’t want to restart, sometimes running this command to refresh the current session works:

newgrp docker
Copied!

Final verification

Once you have reloaded your session, try running the command without sudo:

docker run hello-world

If you see the message “Hello from Docker!”, Congratulations! You have a native, secure, and up-to-date Docker environment on your Linux.