Docker Installation on CentOS 7

Feb 16, 2017 posted by Suhas Kurdukar under IBM

Rapid Application Development with Docker

Introducing Docker

Docker is a container application that makes it simple and easy to run application processes in a container, which are like VMs(Virtual Machines). Docker containers are more resource friendly, more portable and light weighted applications.

How Is It Different from Virtual Machine ?

A fully virtualized system gets its own set of resources allocated to it, and does minimal sharing. You get more isolation, but it is much heavier (requires more resources). With docker you get less isolation, but the containers are lightweight (require fewer resources). So you could easily run thousands of containers on a host, and it won't even blink

A fully virtualized system usually takes few minutes to start, whereas docker/LXC/runC containers take only seconds, and often even less than a second.

In this article, you'll learn how to install and use Docker on an CentOS 7 box.

Installation Prerequisites

1) Centos 7 box

2) Root user access

Steps for Installation

Step #1: Update the package database by running the command sudo yum update -y. 
Step #2: Run the command sudo wget, to add EPEL repository locally.
Step #3: Update patches by running the command sudo yum update -y
Step #4: Install the docker using command sudo yum install docker -y
Step #5: After successful installation of Docker, Start the Docker by running this command sudo systemctl start docker
Step #6: Verify whether the Docker is running properly using the command sudo systemctl status docker

The output is displayed as shown in the screenshot below. 

docker screenshot.png

Executing Docker Command without sudo (optional)

Run the command sudo usermod -aG docker $(whoami), if you want to avoid typing sudo before the docker command, add username to the docker group. 
For this you need to logout the current session and login back as the same user to enable this change. If you want to add another user to the docker group, run this command sudo usermod -G docker username

Working with Docker

Once you'll installed docker, now let's start  exploring the options available in docker. Docker consists of passing it a chain of options and subcommands followed by arguments. The syntax is $ docker [option] [command] [arguments].
If you want to get the all available options. Simply run the docker command $ docker to get the following output. 


Working with Docker Images

To run Docker containers, you must pull the docker images from the docker hub or else need to create an YAML file to customize the docker images of your own containers.

After installation of docker run the command $ docker run hello-world to check whether you can able to pull the docker images from docker hub or not.

Following is the command output.


Using the command $ docker search centos, the script will crawl Docker Hub and returns the available docker centos images list, which includes name, description, stars and some official information. 

Note: In the OFFICIAL column OK indicates that the image sponsored by the official vendor.

Create Docker Images

Run the command $ docker pull ubuntu:latest to pull out the latest version of ubuntu from Docker Hub. Check here for more information on Docker images. To check whether, Image is pulled or not, use the command $ docker images
to display the following output. 


You can further investigate more about the pulled image package by running the command $ docker inspect ubnutu

Running a Docker Container

You can run the container in the following modes:

  • Connected mode: It is run using command docker run -i -t ubuntu:latest /bin/bash/ i means interactive, t means terminal and you are pointing to /bin/bash/.
  • Disconnected mode: Run using command docker run -i -t -d ubuntu:latest /bin/bash/  d means disconnected mode; the docker will be running in the background.

Committing your own changes to the Docker Image 

If you have installed some packages on your container and need to test them in future on another environment, you can commit the changes to docker container and use where ever you want.The command used will be as follows:

$ docker commit -m "Commit Message" -a "Author Name" container-id repository/new_image_name

Example $ docker commit -m "My New version 1.1 container" -a "Kellton"  689347b3d9fh1 latest/centos-mysql

Want to know more about Docker Installation and its programming advantages? Talk to our experts


Share this: