Skip to content

Install Docker on CentOS

Installing Docker on CentOS is fairly straightforward and only takes a few commands. So let’s go through it step by step.

Before we start, we need to remove any Docker dependencies. If you’ve never installed Docker, don’t worry. You can skip this step.

Terminal window
$ sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine

We need to install the yum-utils package. yum-utils gives us the yum-config-manager that we need to set up the repository.

Terminal window
$ sudo yum install -y yum-utils
$ sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo

With yum-utils installed, we can go ahead and install Docker.

Terminal window
$ sudo yum install docker-ce docker-ce-cli containerd.io

Now everything is installed, we should test if it’s working. So start Docker.

Terminal window
$ sudo systemctl start docker

Now, start a container to check that Docker is installed correctly.

Terminal window
$ sudo docker run hello-world

You’ll notice that if you want to start Docker as a non-root user, you’ll probably run into this error.

Terminal window
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.40/containers/json: dial unix /var/run/docker.sock: connect: permission denied

Don’t worry. There’s an easy fix for that. First, let’s create the Docker group.

Terminal window
$ sudo groupadd docker

Then add the non-root user to the group.

Terminal window
$ sudo usermod -aG docker $USER

With all that done, you’ve got Docker set up and ready to use.