How to install Docker and Docker Compose on CentOS 7

How to install Docker and Docker Compose on CentOS 7

Docker is a set of coupled software-as-a-service and platform-as-a-service products that use operating-system-level virtualization to develop and deliver software in packages called containers. The software that hosts the containers is called Docker Engine.

Containers are isolated from each other and bundle their own software, libraries and configuration files; they can communicate with each other through well-defined channels. All containers are run by a single operating-system kernel and are thus more lightweight than virtual machines. Containers are created from images that specify their precise contents. Images are often created by combining and modifying standard images downloaded from public repositories.

Step 1 — Install Docker

Before we install Docker, let’s first update all packages:

$ yum update

Install dependencies:

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

Configure the docker-ce repo:

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

Install docker-ce:

$ yum install docker-ce

Add your user to the docker group:

$ usermod -aG docker $(whoami)

Set Docker to start automatically at boot time:

$ systemctl enable docker

Start the Docker service:

$ systemctl start docker

Verify status of Docker service:

$ systemctl status docker

Step 2 —Check Docker version

To test the version of docker installed, run below command:

# docker --version
Docker version x.x.x-ce, build xxxxxx

Run docker info (or docker version) to view more details of docker

# docker info

Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 17.12.0-ce
Storage Driver: overlay2

Step 3 —Test Docker installation

Test that your installation works by running the simple Docker image, hello-world:

# docker run hello-world

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest: sha256:ca0eeb6fb05351dfc8759c20733c91def84cb8007aa89a5bf606bc8b315b9fc7
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

List the hello-world image that was downloaded to your machine:

# docker image ls

List the hello-world container (spawned by the image) which exits after displaying its message. If it were still running, you would not need the --all option:

# docker container ls --all

54f4984ed6a8     hello-world     "/hello"     20 seconds ago     Exited (0) 19 seconds ago

Summary of docker commands used in our tutorial.

## List Docker CLI commands ##
docker container --help

## Display Docker version and info ##
docker --version
docker version
docker info

## Execute Docker image ##
docker run hello-world

## List Docker images ##
docker image ls

## List Docker containers (running, all, all in quiet mode) ##
docker container ls
docker container ls --all
docker container ls -aq

Step 4 — Install Docker Compose

Install dependencies for Docker Compose:

$ yum install epel-release

Install python-pip:

$ yum install -y python-pip

Next, install Docker Compose:

$ pip install docker-compose

Upgrade Python packages:

$ yum upgrade python*

Verify the Docker Compose installation:

$ docker-compose version

This completes the Docker and Docker-Compose installation tutorial. Enjoy your Docker journey!

Safi Ahmed Choudhury

Safi Ahmed Choudhury

Safi is the founder and chief editor of ZoomTutorials Blog, a leading tutorials and technology blogging site specializing in DevOps, SysAdmin and Cloud Technologies to help IT professionals in their day to day work. He is a Senior Cloud and DevOps Solutions Engineer at a leading eCommerce development Company and has more than 8 years of SysAdmin experience working with Fortune 500 companies to solve their most important IT backbones. Safi lives in Hyderabad with his wife and a son.

Leave a Reply

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