Maab S.
6min Read

How to Install Docker on Linux and Windows

How to Install Docker on Linux and Windows

Docker is an open-source software solution that enables developers to build, deploy, and run applications in self-sufficient containers. The solution comprises of portable container images with all the resources the applications will need to run efficiently.

Advantages of Docker include lower overheads and better usage of resources. Also, it overcomes various compatibility issues that developers and sysadmins encounter when deploying and managing applications on different computer systems. As long as Docker is installed, you can run all the supported images on the computer or server regardless of its hardware or software.

You will learn how to install a package from the official Docker repository which provides the latest stable versions. For all the installations, the files are available from Docker official servers, Ubuntu servers, and other locations. However, only the official repository will have the latest stable versions at any one time. So the best practice, unless unavoidable, is to install from this location.

How to Install Docker on Ubuntu 18.04 and 19.10

In this section, you will learn how to install Docker on Ubuntu 19.10 which is like the process for Ubuntu 18.04. The steps should work for other versions but there could be a few variations.

Prerequisites

  • Ubuntu 18.04 or Ubuntu 19.10
  • sudo user

Step 1: Update the list of packages

We start by updating the local databases. Open the command prompt and run

sudo apt-get update

Step 2: Download and install dependencies

This command installs dependencies to ensure that apt command transfers files securely over https.

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

Step 3: Add GPG key

This is a security feature to ensure the authenticity of the installation files.

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

Step 4: Install Docker repositories

Add the Docker repository to apt sources using the command

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"

Step 5: Update the Repositories

Use the command below to update the repositories just added in the previous command

sudo apt-get update

You may want to confirm that you are running the installation from the Docker official repository using the command;

apt-cache policy docker-ce

If correct, you will see the following output

terminal output

Step 6: Install Docker

Use the command below to install the latest version of Docker.

sudo apt-get install docker-ce

The command installs the latest Docker, after which it starts the daemon and configures it to load automatically when the machine boots. Type Y and press Enter when prompted.

terminal output

After it completes the process, use the command below to verify that the Docker installation is successful, active and running.

sudo systemctl status docker

This will give an output as below

terminal output

The output shows that Docker service is loaded and active, hence indicating a successful installation.

We have used the above steps to successfully install Docker on Ubuntu 18.04 as well as Ubuntu 19.10.


How to Install Docker on CentOS 8

In this section, you will learn how to install Docker on CentOS 8.

Prerequisites

  • CentOS 8
  • Sudo account

Step 1: Update the package database

Let us start by upgrading the package database

sudo yum update

Type Y for yes if prompted to download package updates
Once the update is complete, we will add the Docker repository and install Docker

Step 2: Add and enable official Docker Repository

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

Step 3: Install stable version of the container.id package

The CentOS 8 does not work with some versions of container.id and gives errors when installing with the default package.
There are two ways of overcoming this challenge:
1. Install Docker while skipping unstable dependencies
Or
2. Manually add the stable version of supported dependencies package.

Option 1: Install a stable Docker version while skipping unstable dependencies

Option 1 is to install Docker while automatically skipping packages that have broken dependencies and using the versions that meet certain specifications. To do this we will use the --nobest command

The command allows CentOS to install the Docker version or release meeting certain specifications. If the latest version has broken dependency, such as the containerd.io package, the CentOS will pick the previous stable Docker release.

To do this, use the command

sudo dnf install docker-ce --nobest

The system will scan the packages and dependencies and give you a list of what it will install. It will also show the packages it will skip due to broken dependencies.

terminal output

Type Y when prompted.

This will skip the latest unstable package and use a previous stable version.

terminal output

From above, it shows that the installed Docker version is docker-ce-3:18.09.1-3.el7.x86_64.
Also, the second arrow shows that CentOS skipped the latest Docker version docker-ce-3:19.03.8-3.el7.x86_64

Option 2: Manually install the stable dependencies packages and latest Docker version

This method allows you to install the latest Docker but requires adding the stable container.id package manually.

To add the stable container.id, run

sudo dnf install https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.10-3.2.el7.x86_64.rpm

Install latest Docker version on CentOS 8

Once the container.id is in place, you can now install Docker with the following command.

sudo dnf install docker-ce -y

terminal output
As can be seen, this method has installed the latest Docker version docker-ce-3:19.03.8-3.el7.x86_64

Step 4: Enable and start Docker

You will now enable and start Docker using the command.

sudo systemctl enable --now docker

To confirm that Docker is active and running use

systemctl status docker
terminal output

How to Install Docker on Debian 9 and 10

In this section, we will use the Docker official repository to install the latest version on Debian 10. This guide works for Debian 9 too.

Prerequisites

  • Debian 9 or 10
  • sudo user

Step 1: Update the installed packages

Our first step is to update the list of packages installed on Debian.

sudo apt update

Step 2: Install security package to enforce https

We will now install the files required to ensure that the apt will only use the https connections to transfer files to and from other computers.

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

Step 3: Install GPG key to validate downloads

The GPG key ensures that we only obtain authentic files from the repository. To add the key, run the command below. This will return an OK.

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

Step 4: Add Docker repository to APT sources

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

Step 5: Update the list of packages

Add the just installed Docker packages to the packages database using the following command

sudo apt update

Step 6: Install Docker on Debian

To install Docker now, run;

sudo apt install docker-ce

Type Y and press enter to continue with the installation when prompted to do so.
The above command will install the Docker on Debian after which it configures its engine to start on boot.

Use the command below to check the status and find out if the installation was successful, active, and running.

sudo systemctl status docker

Output

terminal output

How to Install Docker on Windows 2016/2019

The Windows Server 2016 requires the Docker enterprise edition. The instructions below will also work on Windows Server 2019.

Prerequisites

  • Windows Server 2016 (64bit)
  • A user account with administrator rights

In this section, you will learn how to install Docker on Windows Server 2016

Step 1: Install the Docker PowerShell module

Once you log in as an administrator, you will get a Windows command prompt PS C:\Users\Administrator>

At the prompt, type the following command

install-module -name DockerMsftProvider -Force

The command will appear as;

PS C:\Users\Administrator> install-module -name DockerMsftProvider -Force

This will return the following output with a prompt to type Y or N.

terminal output

Type Y to proceed to install and import the NuGet provider. The computer will go back to the command prompt after a short time.

Step 2: Install Docker

Type the following command at the prompt.

PS C:\Users\Administrator>Install-Package Docker -Providername DockerMsftProvider -Force

The command will install the Docker package. If successful, you will see a warning message that requests you to restart the computer.

terminal output

Step 3: Restart the computer and verify Docker is installed

Type the Restart-Computer command at the prompt.

PS C:\Users\Administrator>Restart-Computer

Once the computer restarts, use the following command to verify 1. that Docker is installed successfully and 2. its version.

PS C:\Users\Administrator>docker version
terminal output

The Author

Maab S.

Maab is an experienced software engineer who specializes in explaining technical topics to a wider audience.

More posts from Maab