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 https://download.docker.com/linux/centos/docker-ce.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

CONTAINER ID     IMAGE           COMMAND      CREATED            STATUS
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
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!

Please follow and like us:

ZT Admin

Leave a Reply

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

Next Post

How to Install PHP 7 on CentOS 7 Server

Mon Jul 8 , 2019
PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used server side scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is free to download and use. By default, PHP 5.4 is available in CentOS 7 yum repositories. Here we will discuss how to install […]