Install Docker Service

  1. Install Docker Service Windows
  2. Install Docker Service In Linux

Initially, the inception of Docker containerization started out with Linux as its base platform. However, over the years, Docker and Microsoft have continuously grown their partnership, creating a conveniently consistent interface for building, shipping, and running applications without the usual dependence hurdles associated with virtual machines.

Though a huge number of enterprises are already using Docker on Windows platforms, there has been a number of subtle functionality disparities between Windows and Linux containers. However, Windows Server 2019 (1809 build) has successfully addressed most of the inconsistencies between Docker containers in Linux and Windows environments.

Requirements for Installation of Docker on Windows

Docker containers are powered by a Docker engine. Though initially designed for Linux, extensive work has been done to allow Docker containers to run on Windows and macOS environments.

To run Docker containers on a Windows platform, one prerequisite is the installation of a Windows server. You can do this in a physical server machine, on a cloud environment running in Azure, or an on-premise virtual machine.

Install-Package Docker -ProviderName DockerProvider -RequiredVersion preview. A restart will be required after this operation. Enable LinuxKit system to run Linux containers Environment::SetEnvironmentVariable(“LCOWSUPPORTED”, “1”, “Machine”) Restart the Docker Service after the change above and restart the Service Docker. Install Docker Engine. Estimated reading time: 6 minutes. Supported platforms. Docker Engine is available on a variety of Linux platforms, macOS and Windows 10 through Docker Desktop, and as a static binary installation. Find your preferred operating system below.

  1. Install Docker Engine, changing the path below to the path where you downloaded the Docker package. $ sudo dpkg -i /path/to/package.deb. The Docker daemon starts automatically. Verify that Docker Engine is installed correctly by running the hello-world image. $ sudo docker run hello-world.
  2. Next, follow the instruction below to install the Docker engine on your system. Go to Docker CLI and run the Docker version to verify the version of Docker installation on the system. Congratulations, Docker Installation on Windows is now done, and now, you are ready to build and run Docker images and containers on the Docker ecosystem.

Install the Hyper-V feature on your Windows server 2019

There are two distinct modes to run Decker containers on Windows platforms: Process isolation and Hyper-V isolation. With the Process isolation mode, the Docker containers share the OS kernel with the host platform, hence they are lightweight and identical to Linux system Docker containers.

On the other hand, the running of Docker containers in the Hyper-V mode is confined to a special nominal virtual machine. This enables improved compatibility and secure kernel-level. To run Docker containers in this mode, you must first enable Hyper-V in the host operating system.

The default operation mode for Docker installation on a Windows server is the operation mode (enabling Hyper-V is optional). However, it’s a prerequisite to enable the Hyper-V isolation mode if you need to run Linux containers on a Windows Server interface.

The OS build is another crucial determinant on the need for Hyper-V mode as Windows containers should be of the same build version as the container host OS’s version. Still, Windows container images with a lower build version than the container host OS can run with Hyper-V isolation.

To install Hyper-V on Windows Server 2019, run the PowerShell as Administrator and run the commands below:

Enable-WindowsOptionalFeature –Online -FeatureName Microsoft-Hyper-V –All -NoRestart

Install-WindowsFeature RSAT-Hyper-V-Tools -IncludeAllSubFeature

Next, restart your Windows Server VM.

Prerequisites for the container host

You must enable virtualization in the hosting Windows server platform to utilize Hyper-V isolation in your containers: enable hardware virtualization for a container host running on hardware and nested virtualization in the base interface for a container host running on a cloud space or Hyper-V.

Running Docker Containers on Windows Server 2019

Before running multiple isolated applications using Windows Containers, you need to activate (enable) the containers feature and install Docker on your Windows Server 2019. Here’s the process:

  1. Enable the containers feature in Windows Server 2019.

Run PowerShell as an Administrator and run this command:

Install-Module -Name DockerMsftProvider -Repository PSGallery -Force

This command will install the Docker-Microsoft Package Management Provider from the PowerShell Gallery.

When prompted to install and import NuGet provider, type Y and hit ENTER

  1. Install Docker on your Windows Server 2019

After installing the Containers feature on Windows Server 2019, it’s time to install the latest versions of Docker Engine and Docker Client. Run this command in your PowerShell session:

Install-Package -Name docker -ProviderName DockerMsftProvider

Accept the installation by selecting “Yes”, “Y” or “A” to Agree to all the installation requests.

After the completion of this installation, reboot your computer.

Restart-Computer –Force

You can check your installed Docker version via the PowerShell command:

Get-Package -Name Docker -ProviderName DockerMsftProvider


You can also confirm the installed Docker version using the docker –version command:

docker –version

You can opt to upgrade anytime by running the commands below on PowerShell:

Install-Package -Name Docker -ProviderName DockerMsftProvider -Update -Force

Then start the docker service.

Start-Service Docker

  1. Launch (Run) Docker Containers on Windows Server 2019

Run the following commands on PowerShell:

Start-Service Docker

After starting the Docker Engine service, proceed to download the pre-created .NET sample image on the Docker Hub registry:

docker pull microsoft/dotnet-samples:dotnetapp-nanoserver-1809

After the download, you can deploy a simple Docker container that runs the .Net ‘Hello World’ application:

docker run microsoft/dotnet-samples:dotnetapp-nanoserver-1809

After running the command, an ASCII image will be printed to the shell accompanied by the “Hello” message.

Running Linux Containers on your Window Server 2019

By default, Docker on Windows only runs Windows containers. To launch Linux containers on Windows Server, use the Docker Enterprise Edition Preview that comes with a full LinuxKit system to run Docker Linux containers.

  1. First, uninstall the already installed Docker CE.

Uninstall-Package -Name docker -ProviderName DockerMSFTProvider

  1. Enable Nested Virtualization in case you’re running Docker Containers on a Linux Virtual Machine running on Hyper-V.

Get-VM WinContainerHost Set-VMProcessor -ExposeVirtualizationExtensions $true

Service

NOTE:WinContainerHost is the name of your virtual machine

  1. Install the Module Docker Provider

Install-Module DockerProvider

Install-Package Docker -ProviderName DockerProvider -RequiredVersion preview

A restart will be required after this operation

  1. Enable LinuxKit system to run Linux containers

[Environment]::SetEnvironmentVariable(“LCOW_SUPPORTED”, “1”, “Machine”)

  1. Restart the Docker Service after the change above and restart the Service Docker

Restart-Service docker

To switch back to running Windows containers, execute the following command in PowerShell:

[Environment]::SetEnvironmentVariable(“LCOW_SUPPORTED”, “$null”, “Machine”)

You have finally installed and configured Docker your Windows Server machine to run both Linux and Windows containers. We hope this guide was insightful.

No matter your distribution of choice, you’ll need a 64-bit installation and a kernel at 3.10 or newer. Kernels older than 3.10 do not have the necessary features Docker requires to run containers; data loss and kernel panics occur frequently under certain conditions.

Check your current Linux version with uname -r. You should see something like 3.10.[alphanumeric string].x86_64.

Debian and Ubuntu

Docker runs on:

  • Ubuntu Xenial 16.04 LTS
  • Ubuntu Wily 15.10
  • Ubuntu Trusty 14.04 LTS
  • Ubuntu Precise 12.04 LTS
  • Debian testing stretch
  • Debian 8.0 Jessie
  • Debian 7.0 Wheezy (you must enable backports)

Debian Wheezy

If so, you need to enable backports (if not, ignore this section):

  1. Log into the system and open a terminal with sudo or root privileges (or run sudo -i from your terminal).
  2. Open /etc/apt/sources.list.d/backports.list with your favorite text editor (if the file does not exist, create it).
  3. Remove existing entries.
  4. Add an entry for backports on Debian Wheezy:
  5. Update your packages:

Ubuntu Precise 12.04

If so, you need to make sure you have the 3.13 kernel version. You must upgrade your kernel:

  1. Open a terminal on your system.
  2. Update aptitude:
  3. Install the additional packages:
  4. On a graphical Ubuntu environment, you need to additionally run the following:
  5. Reboot your system:
Docker

Update Aptitude

  1. Log onto your system with a user with sudo privileges.
  2. Open a terminal window.
  3. Purge the older repositories:
  4. Update your packages, making sure apt works with https and the server has CA certificates:
  5. Get the new GPG key:
  6. Open or create the file /etc/apt/sources.list.d/docker.list in your favorite text editor (you need sudo or root for this).
  7. Add an entry for your OS

    VersionSource
    Ubuntu Precise 12.04 LTSdeb https://apt.dockerproject.org/repo ubuntu-precise main
    Ubuntu Trusty 14.04 LTSdeb https://apt.dockerproject.org/repo ubuntu-trusty main
    Ubuntu Wily 15.10 LTSdeb https://apt.dockerproject.org/repo ubuntu-wily main
    Ubuntu Xenial 16.04 LTSdeb https://apt.dockerproject.org/repo ubuntu-xenial main
    Debian Wheezydeb https://apt.dockerproject.org/repo debian-wheezy main
    Debian Jessiedeb https://apt.dockerproject.org/repo debian-jessie main
    Debian Stretch/Siddeb https://apt.dockerproject.org/repo debian-stretch main
  8. Save and close the file.
  9. Update Aptitude again:
  10. Verify Aptitude pulls from the right repository:

Install Docker

Install Docker Service Windows

If you use Ubuntu Trusty, Wily, or Xenial, install the linux-image-extra kernel package:

  1. Install Docker:
  2. Start Docker:
  3. Verify Docker:

The Docker Group

If you prefer, you can set up a docker group to run Docker (instead of root). However, as docker must have sudo access, docker receives the same access as root.

  1. Run the following command to create a Docker group on Ubuntu:
  2. Log out and back in.

  3. Run the following command to create a Docker group on Debian:

    You may specify a user instead of ${USER} if you prefer.

  4. Verify a successful Docker installation:

Red Hat Enterprise Linux (RHEL) and CentOS

Docker runs on RHEL 7 and CentOS 7.

Install Docker

Install with Yum

  1. Log into your system as a user with sudo privileges.
  2. Update your system: sudo yum update -y.
  3. Add the yum repo (use the code below for both RHEL 7 and CentOS 7):
  4. Install Docker:
  5. Start Docker:
  6. Verify Docker:

Install with the Docker Installation Script

  1. Log into your system as a user with sudo privileges.
  2. Update your system:
  3. Run Docker’s installation script:

    This script adds the docker.repo repository and installs Docker.

  4. Start Docker:
  5. Verify Docker:

The Docker Group

If you prefer, you can set up a docker group to run Docker (instead of root). However, as docker must have sudo access, docker receives the same access as root.

  1. Run the following command to create a Docker group and add your user to the group (replace USERNAME with your username):
  2. Log out and back in.
  3. Verify Docker works without sudo:

Install Docker Service In Linux

Start Docker at Boot

Run one of the following:

  • sudo chkconfig docker on
  • sudo systemctl enable docker

Common Issues

Note: Members in the docker group have root privileges. Hardening Docker is covered in a future tutorial.

Ubuntu

Ubuntu Utopic 14.10 and 15.05 exist in Docker’s apt repository without official support. Upgrade to 15.10 or [preferably] 16.04. If you use Ubuntu 12.04, you need to update your kernel.

Debian

If you run Debian Wheezy, you need to update the sources with backports.

“Cannot connect to the Docker daemon. Is ‘docker daemon’ running on this host?”

If you get this error, you need to unset DOCKER_HOST; run unset DOCKER_HOST to clear the variable.

Next: Using Docker Hub
All about how to use Docker's hosted registry.