Overview

In this step, we are going to install Docker. This is one of the steps that will actually not be performed inside of the container image. But, of course, we need Docker on the host in order to run containers.

Install Docker

We now have an updated CentOS operating system. We are ready to install Docker.

  1. First, let's remove any remnants of older versions of Docker to ensure that we run the latest version. From the command prompt, type the following:
sudo yum remove docker docker-common container-selinux docker-selinux docker-engine

Copy & Paste

You can paste this into PuTTY by right-clicking the terminal screen.
  1. We need to install dependencies for Docker:
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
  1. Now, we need to tell CentOS where the Docker repository is located. From the command prompt, type (or paste) the following:
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
  1. Now that the new repository has been added, we need to update the yum package index:
sudo yum makecache fast
  1. We need to query for the latest version of Docker available in the repository:
yum list docker-ce.x86_64  --showduplicates |sort -r
  1. You should see outputed list similar to the following:
docker-ce.x86_64            17.03.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.0.ce-1.el7.centos             docker-ce-stable
  1. The latest version of Docker will be the top line. The version we want is listed in the middle column. In this case it's 17.03.1.ce-1.el7.centos. To install, run the following command replacing <VERSION> with the version listed in the center column.
sudo yum install -y docker-ce-<VERSION>
  1. Installing the Docker engine may take an additional minute or two.

  2. Map the storage device for Docker to use. We'll need to temporarily promote ourselves to the highest user permission level.

sudo bash
mkdir /etc/docker
echo '{ "storage-driver": "devicemapper" }' > /etc/docker/daemon.json
exit
  1. Finally, start Docker:
sudo systemctl start docker

Additional Configuration

To simplify running and managing Docker, there's some additional configuration that we need to implement. While this section is optional, it is recommended to make managing Docker much easier.

Ensure Docker Engine is Running

  1. From the command prompt, type:
sudo systemctl status docker
  1. You should see something similar to the following:
● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2017-06-04 22:38:16 UTC; 4min 10s ago
     Docs: https://docs.docker.com
 Main PID: 32844 (dockerd)
  1. Because the service is running, we can now use the docker command later in this workshop.

Enable Docker Engine at Startup

Let's make sure the Docker engine is configured to run on system startup (and reboot).

  1. From the command prompt, type:
sudo systemctl enable docker
  1. You should see something similar to the following:
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

Elevate Your Privileges

Be default, running the docker command requires root privileges - that is, you have to prefix the command with sudo. It can also be run by a user in the docker group, which is automatically created during the install of Docker. If you attempt to run the docker command without prefixing it with sudo or without being in the docker group, you'll get an output like the following:

docker: Cannot connect to the Docker daemon. Is the docker daemon running on this host?.
See 'docker run --help'.

To avoid typing sudo whenever you run the docker command, add your username to the docker group:

sudo usermod -aG docker $(whoami)

You will then need to log out and back in for the changes to take effect.

If you need to add another user to the docker group (one in which you have not logged in as currently), simply provide that username explicitly in the command:

sudo usermod -aG docker <username>

You've successfully installed the Docker engine. You have also configured it to run at startup and have added yourself to the Docker group so that you have sufficient privileges for running Docker.