How to install Docker in Linux

Docker is a containerized utility that has become very popular, simplifying such tasks. Moreover, when there is a problem with the operating system, instead of installing and reconfiguring the application, users only need to reinstall the operating system, copy the container again.

Virtualization and containers are constantly increasing in popularity. The reason is because they help enhance security and provide mobility to users.

For example, if you use some cloud services, they will help separate data and services more easily. But their use is not limited to that. If you are a Linux application developer, you will quickly realize just how difficult it is to make the application available to all Linux distributions.

When the program you create works in Ubuntu, making it work in Arch Linux, Debian and other distributions is not as simple as you think. Each distribution will be different and you must make adjustments so that the utilities are available in each distribution.

How to install Docker in Linux Picture 1How to install Docker in Linux Picture 1

Containerization process makes development easier and can be deployed anywhere. Instead of relying on the operating system to provide what the application needs, all dependencies are bundled in the container itself. When the container is active, users can move it from one computer to another and between different operating systems easily.

Docker is a containerized utility that has become very popular, simplifying such tasks. Moreover, when there is a problem with the operating system, instead of installing and reconfiguring the application, users only need to reinstall the operating system, copy the container again.

Instructions for installing Docker on some Linux distributions

  1. Delete the old Docker settings
  2. How to install Docker on Ubuntu
  3. How to install Docker on Debian
  4. How to install Docker on Fedora
  5. How to install Docker on Arch Linux

Delete the old Docker settings

This is an optional step, required only if the old version of Docker is installed. They may conflict with new versions, especially if they come from different repositories than what is used here.

On Debian or Ubuntu, 'clean up' everything with:

 sudo apt --purge autoremove docker docker-engine docker.io containerd runc 

On Fedora:

 sudo dnf remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine 

How to install Docker on Ubuntu

Open the terminal and install the prerequisites.

 sudo apt update && sudo apt install software-properties-common gnupg2 curl ca-certificates apt-transport-https 

Check Docker's fingerprint GPG key.

 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg 

How to install Docker in Linux Picture 2How to install Docker in Linux Picture 2

At the time of writing, the fingerprint is: 9DC858229FC7DD38854AE2D88D81803C0EBFCD88. This may change in the future. Check Docker's official website to see if they match. The key is used to verify the electronic signature, so users can ensure the software being installed is legitimate and not malicious software uploaded by the attacker to the server.

Once you've made sure you have the correct key, add it to APT's trusted keys.

 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - 

Add the Docker repository for Ubuntu to the software source.

 sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" 

Install Docker.

 sudo apt update && sudo apt install docker-ce 

If you need Docker Compose, users can install it with:

 sudo apt install docker-compose 

Most Docker commands need to be started with sudo. If you want to avoid having to enter your password each time, add users to the Docker group.

 sudo adduser $USER docker 

Log out of the graphical user interface and log in again. Now, users can use commands like ps docker instead of sudo docker ps.

How to install Docker on Debian

Because Ubuntu is made from Debian, the steps are very similar.

 sudo apt update && sudo apt install software-properties-common apt-transport-https ca-certificates curl gnupg2 

Check the fingerprint to see if it is the same as in the previous section.

 curl -fsSL https://download.docker.com/linux/debian/gpg | gpg 

Add reliable keys.

 curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add - 

Add software source.

 sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" 

Install Docker.

 sudo apt update && sudo apt install docker-ce 

If you need Docker Compose, install it with:

 sudo apt install docker-compose 

To use Docker commands without setting sudo in front:

 sudo adduser $USER docker 

Then log out and log in again.

How to install Docker on Fedora

Install prerequisites.

 sudo dnf install dnf-plugins-core 

Add the Docker software store.

 sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo 

Install Docker.

 sudo dnf install docker-ce 

How to install Docker in Linux Picture 3How to install Docker in Linux Picture 3

On some systems, this will take some time to complete and there seems to be no progress at all. But do not cancel the operation. Of course, the installation process may actually be problematic, but take at least ten minutes to do the work on slow computers.

Allow automatic launch of Docker when booting.

 sudo systemctl start docker.service 

Start Docker.

 sudo systemctl start docker.service 

Add yourself to the Docker group.

 sudo usermod -aG docker $USER 

Log out and log back on to the graphical user interface.

Anyone who needs Docker Compose can install it with:

 sudo dnf install docker-compose 

How to install Docker on Arch Linux

Arch has included Docker in his community repository, so the installation process will be easier.

 sudo pacman -S docker 

How to install Docker in Linux Picture 4How to install Docker in Linux Picture 4

If you need Docker Compose:

 sudo pacman -S docker-compose 

Add yourself to the Docker group:

 sudo usermod -aG docker $USER 

Log out of the graphical user interface and log back in for the installation to take effect.

Allow Docker to automatically start when booting.

 sudo systemctl enable docker 

Start Docker.

 sudo systemctl start docker 

Obviously, this article does not cover all existing distributions. But if you're using something like openSUSE, you may be lucky to find a tutorial page on how to install Docker on that distribution at en.opensuse.org/SDB:Docker

Good luck!

See more:

  1. 5 tips to learn Docker effectively for beginners
  2. How to safely check desktop applications with Docker
  3. 5 useful tips to learn Docker
3.5 ★ | 2 Vote