How To Install and Use Docker on Centos 7

Docker is a set of platform as a service products that use OS-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries, and configuration files; they can communicate with each other through well-defined channels. – Wikipedia


• Learn how to install Docker on Centos 7
• Learn how to use Docker, publish sample website


• CentOS 7 server with internet connectivity
• user with Sudo privileges

Installing Docker on CentOS

Step 1 : Update and Install system packages

Update and install the system packages.

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

Step 2 : Add Docker repository into system

The following command will add the Docker stable repository into your system.

$ sudo yum-config-manager --add-repo

Step 3 : Install Docker CE

After the Docker repository is available on your system, install Docker Community Edition (CE).

$ sudo yum install docker-ce

Step 4 : Start docker daemon and enable on startup

After the installation, start the Docker daemon and enable it so it will automatically start on startup.

$ sudo systemctl start docker
$ sudo systemctl enable docker

Step 5 : Verify Docker service is running

Verify Docker service is running.

$ sudo systemctl status docker

The output should look like below:

Grant Permission To Execute Docker Command

Add user into Docker group so the user can run the command without the need for Sudo privileges. Provide the {username} inside the command.

$ sudo usermod -aG docker {username}

How to Use Docker

In this tutorial, let’s assume that you already have permission to execute the docker command.

Step 1 : Download Image from Docker hub

In this exercise, we are going to deploy three (3) containers. Centos, Alpine, and Network Chuck sample website.

$ docker pull centos
$ docker pull alpine
$ docker pull thenetworkchuck/nccoffee:frenchpress

You may list all downloaded images by using this command.

docker image ls

The output should look as below:

Step 2 : Running Docker Container

By using the downloaded images before, you may proceed to run containers by using the images. The following command line shows how three (3) containers are to be executed.

$ docker run -t -d --name {containername} centos
$ docker run -t -d --name {containername} alpine
$ docker run -t -d -p 80:80 --name {containername} thenetworkchuck/nccoffee:frenchpress

Step 3 : Verify Running Docker Container

You may list all running containers by using this command.

docker ps

The output should look as below:

You may also browse the web deployed in the container:




Hey guys. I'm a Private Cloud Analyst mainly focused on hosting solution which involves hybrid multi-cloud supporting enterprise system.

Cheers, have a good day!

Articles: 4