• Get application security done the right way! Detect, Protect, Monitor, Accelerate, and more…
  • A step-by-step guide to install Docker on your favorite OS.

    Docker is an open-source project that supports building, testing, deploying, and managing applications in self-sufficient, portable containers. Generally, the container images have all the resources that an application requires to run.

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

    Docker is different than traditional VM.

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

    • Ubuntu
    • Debian
    • CentOS
    • Windows

    In most cases, the steps are similar for a particular OS, but there might be some slight variations across different versions.

    Docker installation methods

    Generally, there are three main Docker installation methods, the choice of which depends on the situation and environment, as explained below.

    • Using the Docker repositories: – Easy to install and upgrade method recommended for most online installations.
    • Manual download, installation, and upgrades: – suitable for offline computers that have no access to internet
    • Using automated scripts: for development and testing environments.

    In this guide, we will discuss the installation using the Docker repositories. You will learn how to install and upgrade the tool from the official Docker repositories. Generally, you can also download the files from the operating system’s repository, but this may not have the latest versions hence the need to use the official Docker source whenever possible.

    Install Docker on Ubuntu

    For this article, we will use Ubuntu 18.04.

    Prerequisites

    • Ubuntu 18.04
    • sudo user

    Step 1: Update the local database

    Before installation, start by updating the existing list for 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 each command does;

    • apt-transport-https: Allow apt to transfer files and data over https
    • ca-certificates: make the computer or browser to check security certificates
    • curl: A file transfer tool
    • software-properties-common: adds software management scripts

    Step 3: Add Docker’s GPG Key

    The next would be to add the GPG key – a security feature that ensures the installation files are authentic.

    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 the apt sources.

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

    Step 5: Update Repositories

    Update the database with the Docker packages from the repo you have just added

    sudo apt update

    To ensures that you are running the installation from the official Docker repository, run the command

    apt-cache policy docker-ce

    This should give the following output

    Output of apt-cache policy docker-ce

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

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

    Step 6: Install 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 enable it to automatically start on boot. To confirm that the Docker is active and working, run;

    sudo systemctl status docker

    If installed and running successfully, the command will provide 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 that Docker is active and running.

    Installing Docker on CentOS

    Prerequisites

    • A stable version of CentOS 7
    • Sudo user

    The best practice is to use the latest version of the Docker installation package from the official Docker repository.

    Step 1: Update package database

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

    sudo yum update

    Step 2: Add Docker Repository and install Docker

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

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

    Step 3: Start Docker and check its version

    Once the installation is complete, start the Docker daemon

    sudo systemctl start docker

    Confirm that 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 ensure that you get the latest version, install from the official Docker repository.

    Prerequisites

    1. Debian 9 running
    2. Sudo user

    Step 1: Update system

    First, update the list of installed packages.

    sudo apt update

    Step 2: Install the packages required to run apt to over Https

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

    Step 3: Add 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 the apt sources.

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

    Step 5: Update package database

    We are now going to update the package database with the Docker packages from the repo you have just added.

    sudo apt update

    Step 6: Verify the installation source

    The command below ensures that you are installing the Docker from the official Docker repo instead of Debian’s which may be outdated.

    apt-cache policy docker-ce

    This will return an output similar to the one below. However, Docker’s version number may vary.

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

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

    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, verify that it is running.

    sudo systemctl status docker

    If installed successfully, the output will indicate that the service is active and running.

    Output

    ● 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 server 2016.

    Step 1: Install the Docker Powershell module

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

    If using the administrator account, the command will appear as;

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

    This will give the output as below.

    NuGet provider is required to continue
    PowerShellGet requires NuGet provider version ‘2.8.5.201’ or newer to interact with NuGet-based repositories. The NuGet
    provider must be available in ‘C:\Program Files\PackageManagement\ProviderAssemblies’ or
    ‘C:\Users\Administrator\AppData\Local\PackageManagement\ProviderAssemblies’. You can also install the NuGet provider by
    running ‘Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force’. Do you want PowerShellGet to install
    and import the NuGet provider now?
    [Y] Yes [N] No [S] Suspend [?] Help (default is “Y”): y
    Type Y for Yes

    Step 2 Install Docker Package

    After the module is in place, we are now ready to install the Docker package.

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

    This will install the Docker package on the computer but it will not start the service. As such, you must restart the computer to enable the container feature.

    PS C:\Users\Administrator>Restart-Computer

    After the restart, verify the installation and version by running

    PS C:\Users\Administrator>docker-version

    Output

    Client: Docker Engine – Enterprise
    Version: 19.03.5
    API version: 1.40
    Go version: go1.12.12
    Git commit: 2ee0c57608
    Built: 11/13/2019 08:00:16
    OS/Arch: windows/amd64
    Experimental: false
    Server: Docker Engine – Enterprise
    Engine:
    Version: 19.03.5
    API version: 1.40 (minimum version 1.24)
    Go version: go1.12.12
    Git commit: 2ee0c57608
    Built: 11/13/2019 07:58:51
    OS/Arch: windows/amd64
    Experimental: false
    
    PS C:\Users\Administrator>

    To test Docker with a typical image, run the command

    docker run hello-world:nanoserver-sac2016

    If installed and running properly, the command will give the following output.

    PS C:\Users\Administrator> docker run hello-world:nanoserver-sac2016
    
    Hello 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 the
    executable that produces the output you are currently reading.
    4. The Docker daemon streamed that output to the Docker client, which sent it
    to 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 powershell
    Share 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/

    Please note that you must use a windows container image by default. In case you need to run Linux container images, use the Docker Daemon in the experimental mode, which is available in the desktop version.

    Conclusion

    I hope now you know how easy is to install Docker. Once you installed, play around with it to get familiarize and if you need some video-based training then check out this course.