Docker Installation — CentOS/RHEL

Avishek Roy
teckdevops
Published in
5 min readApr 28, 2019

Quick docker overview, installation and startup command guide for CentOS/RHEL7 .

Docker ?

Docker is a virtualization tool i.e. used to perform OS virtualization and is a great tool to create , deploy and run application by using light weighted software packages called as containers.

Docker containers shares the underlying resources of the host and contain only bare necessary resources and libraries that is required to bring up the application.

Containers are created from images , A Docker image is a read-only template that is used to build containers. In layman terms, image is an application that we want to run and container is an instance of that image that will run as a process.

This blog is an entry point into the world of docker where we will explore how to get started with docker via installation on Cent-OS/RHEL7 and running some basic docker commands. So, let’s start with containerization!

1. Install docker

Docker package is incorporated in Linux repositories so, installation is quite simple and easy.

2. Verify Installation

3. Start docker daemon

4. Docker Process & Commands

The simplest way to spin up a container is via docker run command. docker is an executable program which provided various options and features.

docker help
docker help commands

Now to start a container , use docker run Or docker container run command. Below is command for same i.e. to spin up a nginx container.

nginx container
docker ps

Background action when you run docker run !

  • docker looks for image locally.
  • If [No found] , then looks in remote image repository(docker hub).
  • If [Found] , then download latest version.
  • Create new container based on downloaded image and prepares to start.
  • Assigns a virtual IP inside docker container.
  • Opens up port 80 on host and maps it to port 80 inside container.
  • Starts container by using the CMD in the image Dockerfile.

Now let’s try out accessing nginx on http://systemip:80.

nginx

Command Overview

d → to run container in a detach mode i.e. to run container @ background

p → port i.e. <srcport:dstport>

name → name of the container

nginx → docker image

More Commands..

More docker commands
  • docker ps → check for running docker process
  • docker images → list downloaded images
  • docker ls → same as docker ps
  • docker search <image/application> → Search for available images.
  • docker pull <image/application> → Pull images from docker hub.
docker search
docker pull

Docker containers are light weighted and therefore easy to deploy and ship. Would you believe that the size of an alpine (a linux distro) docker image is less than 6 MB !

alpine

So, just imagine , with docker you can run a linux environment with 6 MB of disk space and i.e. on a windows machine too.

Running a alpine container

Now let’s run an alpine container using docker run command and jump into the busy-box.

run alpine

→ Running a command into the container from the host machine.

From the host

→ Login into the container and running a command into the container

From the container

5. Cleanup

Use docker stop , rm commands to stop and remove the running container. please note it will flush out all the changes done with/on the container while in running state.

remove container

In the last step we removed the container but a docker image is still dangling around. To remove an image use docker rmi i.e. remove image command.

remove image

Signing off with the below docker command snippet i.e. used over this blog for reference and c&p.

Docker Commands$ docker ps 
$ docker images
$ docker pull alpine
$ docker run -d -t --name alpine alpine
$ docker run -d --name nginxcontainer -p 80:80 nginx
$ docker exec -it alpine /bin/sh
$ docker stop nginx alpine
$ docker rm alpine nginx
$ docker rmi alpine nginx

Happy Reading! Adios !

— A blog by teckdevOps

--

--