First, we will need to install some required packages. Open a terminal window and enter the following command:
# installing required packages
sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
This will make sure that we have both the yum-config-manager utility and the device mapper storage driver installed on the system. It is illustrated in the following screenshot:
Note that your installation of CentOS 7 may already have these installed, and in that case the yum install command will report that there is nothing to do.
Next, we will set up the CentOS stable repository for Docker CE.
It is worth noting that you will still need to set up the stable repository even if you want to install the edge releases.
Enter the following command to set up the stable repository:
# adding the docker-ce repo
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
Optionally, if you want to use the edge release, you can enable it with the following command:
# enable edge releases
sudo yum-config-manager --enable docker-ce-edge
Similarly, you can disable access to the edge release with this command:
# disable edge releases
sudo yum-config-manager --disable docker-ce-edge
Now the fun begins... We are going to install Docker CE. To do so, enter the following command:
# install docker
sudo yum -y install docker-ce
If you get an error about the need to have container-selinux installed, use this command to install it, then try again:
# install container-selinux
sudo yum -y --enablerepo=rhui-REGION-rhel-server-extras \
install container-selinux
sudo yum -y install docker-ce
There you have it! Installing Docker CE was way easier than you thought it was going to be, right?
Let's use the most basic method to confirm a successful install, by issuing the version command.
This command validates that we installed Docker CE, and shows us what version of Docker was just installed. Enter the following command:
# validate install with version command
docker --version
The latest version of Docker CE, at the time of writing, is 18.03.1:
We have one more critical step. Although Docker CE is installed, the Docker daemon has not yet been started. To start it, we need to issue the following command:
# start docker deamon
sudo systemctl start docker
It should quietly start up, looking something like this:
We saw how to validate that Docker installed using the version command. That is a great quick test, but there is an easy way to confirm not just the install, but that everything started and is working as expected, which is by running our first Docker container.
Let's issue the following command to run the hello-world container:
# run a test container
sudo docker run hello-world
If all is well, you will see something like the following:
We've got Docker CE installed on our CentOS workstation, and it is already working and running containers. We are off to a great start. Now that we know how to do an install using the Docker repositories, let's have a look at how to manually install using a downloaded RPM.