Docker has quickly become the most popular program for containerization. For CentOS users, that means an increase in the need to install Docker on CentOS. Luckily, the process for Docker installation on CentOS 6, CentOS 7, and CentOS 8 is fairly simple.
In this blog, we’ll look at how to complete a successful CentOS Docker installation for CentOS 6, 7, and 8, then look at some Docker basics that can help you to get started.
Docker is a program for building, running, and managing containers.
Containers are run as namespaces under the linux kernel, and are implemented with images that contain the filesystems and all data needed to run the process in the container. This mostly separates the running process from other resources on the system.
This is simplified, of course, because this article isn’t really about what docker is and how to use it, but how to install it under CentOS.
Installing Docker on CentOS varies from version to version. Below you’ll find instructions on how to install Docker on CentOS versions 6, 7, and 8.
CentOS 6 will reach end of life on November 30, 2020, so there will be no more updates. Docker CE is not available for CentOS 6. The best we can do is install an old version from docker.com, which is version 1.7.0-1:
yum install -y https://get.docker.com/rpm/1.7.0/centos-6/RPMS/x86_64/docker-engine-1.7.0-1.el6.x86_64.rpm
However, CentOS 6 is no longer recommended since it will no longer receive security fixes or updates.
The default docker version (with CentOS 7) is 2:1.13.1-162git64e9980, which is quite old. We will install the latest version from main docker repository. First we install yum-utils, which gives a command for easily adding repositories. Then we use that command to add the docker repo, then install docker-ce:
yum install -y yum-utils
yum install -y docker-ce
The version installed on my test CentOS 7 instance is docker-ce-19.03.13-3 .
Centos 8 installs podman by default. It is nearly a drop-in replacement for docker, that doesn’t use a service to run. However we are not covering podman in this article, so we will remove it to install docker. DNF is a replacement for yum. Yum is an alternate name for dnf in CentOS 8.
dnf remove -y podman buildah
# This is the same as dnf-utils, this may already be installed
dnf install -y yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
dnf install -y docker-ce
Docker uses some kernel modules, like the overlay fs module, so make sure your system has module loading enabled. Make sure the following option is set to 0:
kernel.modules_disabled = 0
Otherwise starting the docker service will fail. Then you can start docker and make sure it starts at boot time.
On CentOS 7/8:
systemctl start docker
systemctl enable docker
systemctl status docker
On CentOS 6:
service docker start
service docker status
By default only root can run docker commands. To allow users other than root to run docker, add them to the docker group:
usermd -G docker -a loginid
This will add the user to the docker group. The -a option appends the group, instead of replacing the groups. Test by running a simple hello-world app:
docker run hello-world
To show some commands, we will run a simple container that stays running until you stop it. In one shell, type:
docker run -p 80:80 nginx
That says to run the nginx container (a web server) and map port 80 on the host to port 80 in the container. You will see some ouput, then:
/docker-entrypoint.sh: Configuration complete; ready for start up
In another shell, test with:
curl -v localhost
Also you will see a log entry for the nginx container. Show the containers running with docker ps:
#d50f34872cea inginx "/docker-entrypoint..." 2 minutes ago Up 2 minutes 0.0.0.0:80->80/tcp crazy_heisenberg
If you don’t give a container a name, docker will give it a random name. You can reference a container with either the CONTAINER ID or the name.
docker logs crazy_heisenberg
Docker logs shows the log information, which was also printed to the terminal before. docker inspect will show lots of internal information about the container.
You now have a working Docker installation. Docker will work both with SELinux and without. Extra features are enabled with SELinux to allow container separation.
For those exploring their options for containerization or container orchestration, OpenLogic architects can provide expert guidance and support for implementing Docker, Kubernetes, and more. OpenLogic architects are also skilled in CentOS, offering many CentOS services and support.
Talk to an expert today to learn how we can help you with everything from open source containers to operating systems — and beyond.
TALK TO AN EXPERT
What is the future of CentOS? Watch the webinar below to hear from our experts.
Looking for additional resources on popular open source containerization technologies? Be sure to look at these options from our open source experts:
Lance has been working in the IT field for over 30 years, most of it concentrated on data centers and infrastructure. For the past 10 years he has focused on SaaS infrastructure, ensuring reliability, high availability, and scalability of systems. He has been working with CentOS related distributions for the past 25 years.