I’ve recently started to study for the Docker Certified Associate certification as a way to help cement the knowledge I’ve picked up whilst using containers over the past 18 months or so. Over the coming weeks/months I’ll be putting some posts together here to cover the study objectives required for taking the certification exam. If you’re new to Docker certification, you can find out more about it here, whilst the study guide, which lists the required knowledge areas, can be found here. I’ll be referring to this document through out this series of posts, whilst focusing on giving practical examples, whilst providing links to supporting documentation.
As a starter, I’m going to run through how to install Docker on Centos 7.
Installing Docker Community Edition on Centos 7
The first step is to install the packages that Docker is dependent on. To do so run:
sudo yum install -y device-mapper-persistent-data lvm2
On my Centos 7 build, the packages were already installed:
Package device-mapper-persistent-data-0.7.3-3.el7.x86_64 already installed and latest version Package 7:lvm2-2.02.180-10.el7_6.8.x86_64 already installed and latest version
But this may not always be the case, so it’s worth confirming. The next step is to add the Docker CE repository, so that yum will be able to download and install the Docker CE application. To add the repo, run the following:
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
You should get some feedback to show that the repo has downloaded:
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo repo saved to /etc/yum.repos.d/docker-ce.repo
We can now go ahead and install the Docker CE and containerd.io. Note that containerd.io is a package that is used by Docker , so we are installing it along with Docker CE . This article (https://blog.docker.com/2017/08/what-is-containerd-runtime/) covers what containerd.io is and what it does. To perform the install, run the following:
sudo yum install -y docker-ce-18.09.5 docker-ce-cli-18.09.5 containerd.io
With Docker CE installed, we now need to start the service, and enable it to start next time the system reboots. To do so, run the following systemctl commands:
sudo systemctl start docker sudo systemctl enable docker
We can check that it’s now running by using the systemctl status command:
[user@docker1]$ sudo systemctl status docker ● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled) Active: active (running) since Mon 2019-08-19 14:21:27 UTC; 11s ago Docs: https://docs.docker.com Main PID: 2273 (dockerd) CGroup: /system.slice/docker.service └─2273 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
The last step I want to cover here is adding a non-root user to the docker group, in order to enable the user to run docker without having to use sudo:
sudo usermod -a -G docker user1
Now ‘user1’ will be able to run Docker commands, as a member of the Docker group. We can test this by running the ‘hello-world’ container, which is used for testing Docker:
docker run hello-world
If all is working as expected, the container will download and the following will be displayed:
Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 1b930d010525: Pull complete Status: Downloaded newer image for hello-world:latest 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. (amd64) 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 an Ubuntu container with: $ docker run -it ubuntu bash 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/
And that’s it! We now have a working Docker CE installation.
Useful Links and Resources
https://docs.docker.com/install/
https://docs.docker.com/install/linux/docker-ce/centos/
Note:
You could combine the commands listed in this article to install Docker CE using a simple shell script, for example:
#!/bin/bash sudo yum install -y device-mapper-persistent-data lvm2 sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo sudo yum install -y docker-ce-18.09.5 docker-ce-cli-18.09.5 containerd.io sudo systemctl start docker sudo systemctl enable docker sudo usermod -a -G docker $USER