Use and install Docker on Linux Step by Step

Within this new guide today we will talk about how to use and install Docker on Linux, one of the most popular tools on the operating system.

Docker: what it is

Docker is a powerful tool that works on almost all Linux distributions, used by users to quickly and easily download many images. Docker is considered one of the best tools that Linux has to offer. However, it is not supplied as standard with the distros.

The fact that Docker is not pre-installed is on the one hand understandable as it is a fairly complex tool. At this time, the program can be easily downloaded and installed on most popular Linux distros such as UbuntuDebian and Fedora. However, the possibility of installing it via Snap has recently been introduced.

How to install Docker on Ubuntu

In case you were a Ubuntu equipped computer, then keep reading the next few lines to find out how to install Docker.

However, before doing this, you need to update the Ubuntu apt package cache and install any software updates. To do this, run sudo apt update first and then sudo apt upgrade. Once the system has been updated correctly, you will need to install some important packages to allow the Ubuntu package manager to better interact with the HTTPS download. To do this, open the terminal and type in:

sudo apt-get install

apt-transport-https

ca-certificates

curl

software-properties-common

The next step to take is to add the GPG key to the Docker software repository. This is a very important operation since Ubuntu will not install the program without it. So, use the command curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -.

Once the key is downloaded, add the Docker CE software repository to Ubuntu using the command:

sudo add-apt-repository

"Deb [arch = amd64] https://download.docker.com/linux/ubuntu

$ (lsb_release -cs)

stable"

Finally, update the Ubuntu software sources again and install the Docker software to complete the installation process using the command sudo apt update && sudo apt install docker-ce.

How to install Docker on Debian

Before installing Docker on Debian, you need to update the system to allow the program to work properly on your computer. So, run sudo apt-get update first and then sudo apt-get upgrade.

Once this is done, you need to install some tools to correctly download the Docker packages.

If you have the Stretch or Jessie versions, use the command:

sudo apt-get install

apt-transport-https

ca-certificates

curl

gnupg2

software-properties-common

If you have Debian Wheezy, instead, take advantage of the command:

sudo apt-get install

apt-transport-https

ca-certificates

curl

python-software-properties

Once added the tools you need to install the GPG repository key on Debian. Be careful because this is a fundamental step that will allow you to install the program correctly. To do this, use the command curl -fsSL https://download.docker.com/linux/$ (. / Etc / os-release; echo “$ ID”) / gpg | sudo apt-key add – .

Now, you need to add the Docker CE software repository to the list of Debian sources through the command:

sudo add-apt-repository

"Deb [arch = amd64] https://download.docker.com/linux/$ (. / Etc / os-release; echo" $ ID ")

$ (lsb_release -cs)

stable"

Now, you need to update the Linux distro software sources a second time and proceed with the Docker installation. You can do this through the commands sudo apt-get update && sudo apt-get install docker-ce.

How to install Docker on Fedora

Before proceeding with the installation of Docker on Fedora, you need to install some Dnf plugins as they are important because they allow the installation of the software in a much simpler way. So to install the Dnf plugins, use the command sudo dnf -y install dnf-plugins-core.

Once installed correctly, you need to add the current software repository to the computer using the command:

sudo dnf config-manager

-add-repo

https://download.docker.com/linux/fedora/docker-ce.repo

The addition of the official software repository for Dnf and Fedora will allow for regular Docker software updates.

In conclusion, install the program directly from the Fedora package manager to complete the operation using the sudo dnf install docker-ce command.

How to install Docker via Snap

If you fail to install Docker correctly on the Linux distribution, you can use Snap. Before proceeding with the installation of the Snap version on your Linux PC, it is necessary to install and configure Snapd. In this case, we recommend that you take our dedicated guide as a reference.

  • How to use and install Snap packages on Linux

Once this is done, use the sudo snap install docker –edge command to install Docker via Snap.

At this point, you need to complete the configuration process using the commands listed below, taking care to replace the username in the third command with the username you intend to use on Docker.

sudo snap connect docker: home

sudo groupadd –system docker

sudo usermod -a -G docker username

newgrp docker

sudo snap disable docker

sudo snap enable docker

How to use Docker on Linux

Once Docker is properly installed on your Linux PC, you can easily upload or download your favorite images without spending a penny using the Docker Hub website. To get a Docker image on Linux via Docker Hub, you must use the pull command.

Below are the steps to follow:

  • Open the default browser, connect to the Web site of Docker Hub, and then click on Sign Up at the top right.
  • On the new page that appears, register a new account by filling in the required fields, confirming your identity and pressing Continue.
  • Once the creation of the new account is complete, return to the Docker Hub home page and this time press on Sign In at the top right and access your account by filling in the required fields.
  • In the next step, you are ready to start downloading Docker images. To do this, locate the search field at the top left and type in the term corresponding to the image you want to download.
  • Once you have chosen the image, click on it to access the dedicated page.
  • At this point, locate the Copy and paste to pull this image section at the top right where a little further down you will find the official command to download it (eg docker pull mysql ).
  • Now, press on ‘icon of the two sheets to copy and then paste the command in the terminal using the key combination Ctrl + Shift + V.
  • Complete the operation by giving consent to execute the pull command so that you can download the image. Once the download is complete, refer to the image page because you will find the official instructions for how to use it.

How to uninstall a Docker image

To delete a Docker image installed on Linux you need to use the rmi command. However, before removing it, you need to run the images command to see the name of the images in the system.

Therefore, execute the command docker images in the terminal . After that, take a look at the list that appears and copy the name of the image you want to remove. Once this is done, enter the command docker rmi in the window followed by the name of the image (eg docker rmi mysql ).

Doubts or problems? We help you!

If you have any doubt or query related to article then feel free to contact us.

Tarun Bhardwaj: