How to install Docker on Ubuntu, CentOS, Debian and Windows

A step by step guide to installing Docker on your favorite OS.

Docker is an open source project that supports building, testing, deploying, and managing applications in self-contained, portable containers. Typically, container images contain all the resources an application needs to run.

Today, Docker has become a popular tool for deploying and managing applications as containers while solving compatibility issues. This technology allows you to install applications and services on a wide range of computers, regardless of the underlying hardware and operating systems. Therefore, you can run such images on different computer systems as long as Docker is installed. Typical images include Nginx, MariaDB, WordPress, and more.

Docker is different from a traditional virtual machine.

In this guide, you will learn how to install Docker on the following operating systems.

  • Ubuntu
  • Debian
  • CentOS
  • Window

In most cases, the steps are the same for a specific OS, but there may be slight differences between different versions.

Ways to install docker

Generally, there are three main methods for installing Docker, depending on your situation and environment, as described below.

  • Using Docker repositories: - Easy installation and upgrade method recommended for most online installations.
  • Manual download, installation and update: - suitable for stand-alone computers that do not have access to the Internet.
  • Use of automated scripts: for development and testing environments.

In this guide, we will discuss installation using Docker repositories. You will learn how to install and update the tool from the official Docker repositories. You can usually also download files from the operating system repository, but it may not have the latest versions, so you should use the official Docker source whenever possible.

Install Docker on Ubuntu

In this article, we will be using Ubuntu 18.04.

Prerequisites

Step 1: Update the local database.

Before installing, start by updating the existing list of packages.

sudo apt update

Step 2: Install dependencies that support https

Install packages that will allow apt to transfer files over https

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

This is what every team does;

  • apt-transport-https: Allow apt to transfer files and data over https.
  • ca-certificates: force the computer or browser to validate security certificates
  • curl: file transfer tool
  • software-properties-common: adds software control scripts

Step 3: Add the GPG Docker Key

The next step is to add a GPG key, a security feature that guarantees the authenticity of the installation files.

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

Step 4: Install the Docker Repository

In this step, use the command below to add the Docker repository to apt sources.

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

Step 5: Restore the repositories

Update the database with Docker packages from the newly added repository.

sudo apt update

To make sure you are running the installation from the official Docker repository, run the command

apt-cache policy docker-ce

This should give the following output

docker-ce apt-cache policy output

docker-ce:  Installed: (none)  Candidate: 5:19.03.5~3-0~ubuntu-bionic  Version table: 5:19.03.5~3-0~ubuntu-bionic 500500 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages 5:19.03.4~3-0~ubuntu-bionic 500500 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages 5:19.03.3~3-0~ubuntu-bionic 500

You will notice from the output that docker-ce is not installed yet. However, the output will show the target operating system and Docker version number. Please note that version numbers may differ depending on the installation time.

Step 6: Install the latest version of Docker

Once confirmed, use the following command to install Docker.

sudo apt install docker-ce

This will install Docker, start the daemon, and let it automatically start on boot. To make sure Docker is up and running, run;

sudo systemctl status docker

If installed and run successfully, the command will produce the following output

    $ sudo systemctl status docker● docker.service - Docker Application Container Engine   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: e   Active: active (running) since Sat 2019-12-14 07:46:40 UTC; 50s ago Docs: https://docs.docker.com Main PID: 2071 (dockerd)Tasks: 8   CGroup: /system.slice/docker.service   └─2071 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/contain

This part of the output shows that the installation was successful and Docker is up and running.

Installing Docker on CentOS

Prerequisites

  • Stable version of CentOS 7
  • Sudo User

It's best to use the latest Docker installation package from the official Docker repository.

Step 1: Update the package database.

The first step is to update the package database using the command.

sudo yum update

Step 2: Add a Docker Repository and Install Docker

After the update, we will add the official Docker repository and download and install the latest version of Docker. To do this, use the command;

curl -fsSL https://get.docker.com/ | sh

Step 3: Run Docker and check its version

Once the installation is complete, start the Docker daemon.

sudo systemctl start docker

Make sure Docker is running

sudo systemctl status docker

This should provide the following output

docker.service - Docker Application Container Engine   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)   Active: active (running) since Mon 2019-12-09 09:54:50 UTC; 7s ago Docs: https://docs.docker.com Main PID: 9194 (dockerd)Tasks: 8   Memory: 44.0M   CGroup: /system.slice/docker.service   └─9194 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/cont...

Installing Docker on Debian

To make sure you're getting the latest version, install it from the official Docker repository.

Prerequisites

  • Debian 9 works
  • Sudo User

Step 1: Update the system

First update the list of installed packages.

sudo apt update

Step 2: Install the packages required to run apt over HTTPS.

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

Step 3: Add a GPG Key

Now we need to add the GPG key from Docker to our Debian system. This ensures that the downloads are valid.

To add the GPG key for the official Docker repository, run

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

Step 4: Add the Docker repository to the APT sources.

In this step, you will add the 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 package database

Now we are going to update the package database with the Docker packages from the repository you just added.

sudo apt update

Step 6: Check the installation source

The command below ensures that you are installing Docker from the official Docker repository and not Debian, which may be out of date.

apt-cache policy docker-ce

This will return output similar to the one below. However, the Docker version number may differ.

  Installed: (none)  Candidate: 5:19.03.5~3-0~debian-stretch  Version table: 5:19.03.5~3-0~debian-stretch 500500 https://download.docker.com/linux/debian stretch/stable amd64 Packages 5:19.03.4~3-0~debian-stretch 500500 https://download.docker.com/linux/debian stretch/stable amd64 Packages 5:19.03.3~3-0~debian-stretch 500500 https://download.docker.com/linux/debian stretch/stable amd64 Packages 5:19.03.2~3-0~debian-stretch 500500 https://download.docker.com/linux/debian stretch/stable amd64 Packages......17.03.1~ce-0~debian-stretch 500500 https://download.docker.com/linux/debian stretch/stable amd64 Packages 17.03.0~ce-0~debian-stretch 500500 https://download.docker.com/linux/debian stretch/stable amd64 Packages

As you can see, docker-ce is not installed yet. The output shows that the installation is from the official Docker repository for Debian 9 (stretched).

Step 7: Install Docker

We are now ready to install Docker using the command below.

sudo apt install docker-ce

This will install Docker, start the engine, and configure it to always start on boot. After the installation is complete, make sure it is running.

sudo systemctl status docker

If the installation is successful, the output will indicate that the service is up and running.

Exit

● docker.service - Docker Application Container Engine   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: e   Active: active (running) since Mon 2019-12-09 11:48:32 UTC; 41s ago Docs: https://docs.docker.com Main PID: 17486 (dockerd)   CGroup: /system.slice/docker.service   └─17486 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/contain

install docker on windows

Let's see how to install Docker enterprise edition on Windows 2016 server.

Step 1: Install the Docker Powershell Module

Open a Windows PowerShell command prompt with an administrator account and use the command below to install the DockerMsftProvider module. This is a Docker Powershell module for finding, installing and updating Docker images.

When using an administrator account, the command will appear as;

PS C:UsersAdministrator> install-module -name DockerMsftProvider -Force

This will give the result as shown below.

NuGet provider is required to continuePowerShellGet requires NuGet provider version ‘2.8.5.201’ or newer to interact with NuGet-based repositories. The NuGetprovider must be available in ‘C:Program FilesPackageManagementProviderAssemblies’ or‘C:UsersAdministratorAppDataLocalPackageManagementProviderAssemblies’. You can also install the NuGet provider byrunning ‘Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force’. Do you want PowerShellGet to installand import the NuGet provider now?[Y] Yes [N] No [S] Suspend [?] Help (default is “Y”): yType Y for Yes

Step 2: Install the Docker Package

Once the module is installed, we are ready to install the Docker package.

PS C:UsersAdministrator>Install-Package Docker –Providername DockerMsftProvider –Force

This will install the Docker package on the machine but will not start the service. Thus, you must restart your computer to enable the container feature.

PS C:UsersAdministrator>Restart-Computer

After reboot, check the installation and version by running

PS C:UsersAdministrator>docker-version

Exit

Client: Docker Engine – EnterpriseVersion: 19.03.5API version: 1.40Go version: go1.12.12Git commit: 2ee0c57608Built: 11/13/2019 08:00:16OS/Arch: windows/amd64Experimental: falseServer: Docker Engine – EnterpriseEngine:Version: 19.03.5API version: 1.40 (minimum version 1.24)Go version: go1.12.12Git commit: 2ee0c57608Built: 11/13/2019 07:58:51OS/Arch: windows/amd64Experimental: falsePS C:UsersAdministrator>

To test Docker on a typical image, run the command

docker run hello-world:nanoserver-sac2016

If it is installed and working correctly, the command will produce the following output.

PS C:UsersAdministrator> docker run hello-world:nanoserver-sac2016Hello from Docker!This message shows that your installation appears to be working correctly.To generate this message, Docker took the following steps:1. The Docker client contacted the Docker daemon.2. The Docker daemon pulled the “hello-world” image from the Docker Hub.(windows-amd64, nanoserver-sac2016)3. The Docker daemon created a new container from that image which runs theexecutable that produces the output you are currently reading.4. The Docker daemon streamed that output to the Docker client, which sent itto your terminal.To try something more ambitious, you can run a Windows Server container with:PS C:> docker run -it mcr.microsoft.com/windows/servercore powershellShare images, automate workflows, and more with a free Docker ID:https://hub.docker.com/For more examples and ideas, visit:https://docs.docker.com/get-started/

Note that you should use the Windows container image by default. If you need to run Linux container images, use the Docker Daemon in experimental mode, which is available in the desktop version.

Summary

Hopefully now you know how easy it is to install Docker. Once you've installed it, play around with it to familiarize yourself

Related posts