How to Install Docker CE on CentOS 7

I’ve worked on Docker for a while but I have never written a blog about Docker as much as I’ve wanted. I will blog about how to install Docker CE on CentOS 7. I’m writing this blog based on the official documentation here.

Prerequisite

There are a few prerequisite packages to install.

$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2

Install Repository

We have to register Docker’s yum repository now.

$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

Install and Start Docker CE

$ sudo yum install docker-ce docker-ce-cli containerd.io
$ sudo systemctl enable docker
$ sudo systemctl start docker

Test Docker

Run the following command to test if Docker was installed correctly.

$ sudo docker run hello-world

You will see an output like the image below.

It will download the hello-world image and run it.

If you execute the command below, you will see the container that ran and exited.

$ sudo docker ps -a

The container is no longer useful, so let’s remove it. Replace the [CONTAINER ID] with what you see in the result of the previous command.

$ sudo docker rm [CONTAINER ID]

Run Docker Commands without sudo

It’s quite a bit more typing if you have to “sudo” for Docker commands on top of entering your password often by using it. There is a way to omit sudo when running Docker commands.

$ sudo usermod -aG docker $USER
$ exit

You have to exit the SSH session and log back in to be able to execute docker commands without sudo.

Removing Downloaded Image

Let’s see the list of images on the Docker host by executing the command below. I will omit sudo from here on.

$ docker images

Let’s remove it because we really don’t need it anymore.

$ docker rmi [IMAGE ID]

Recap

We went over the installation and the very basic test of Docker. What I’ve written here should get you going with Docker on CentOS 7.

Author: admin

A software engineer in greater Seattle area

Leave a Reply

Your email address will not be published. Required fields are marked *