Install & Run Docker Container on CentOS

Install & Run Docker Container on CentOS

·

2 min read

What is docker?

Docker is an open source software platform which is used to build, deploy and run applications by packaging into containers. These containers have all the binaries, libraries, dependencies, tools and runtime which are necessary for running those packaged applications.

image.png

These containers communicates with the kernel of host operating system to request and use the resources.

image.png

Docker Images:

The Docker images are template files which defines all the components and configuration details, which will be a part of running container. These images can either be downloaded from any public / private docker registry or we can create our own docker images using Dockerfile.

Docker Registry:

The docker registry is a repository for docker container images. A very famous registry is Docker Hub, from where we can pull or push the docker container images. Some organization use their own private registry for security and other reasons.

image.png

Dockerfile:

This is a very simple text file where you can specify the commands to build Docker images.

Install & Run Docker Container on CentOS

Step-1: Update the package manager database.

# yum check-update

image.png

Step-2: Installation of Prerequisite Packages.

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

image.png

Step-3: Add the CentOS Repository for Docker

# yum-config-manager --add-repo download.docker.com/linux/centos/docker-ce...

image.png

Step-4: Docker Installation

# yum install docker

image.png

Step-5: Start Docker daemon

Now the docker daemon needs to be started. For this run the following command:

# systemctl start docker

image.png

Step-6: Configure Docker to Start Automatically

To make sure that docker starts every time when the server reboot, run the following command:

# systemctl enable docker

image.png

Step-7: Verify the Docker Status

To check the docker status, run the following command:

# systemctl status docker

image.png

Step-8: Pull the docker images

# docker pull hello-world

image.png

# docker pull centos image.png

Step-9: See the downloaded Docker images

# docker images

image.png

Step-10: Run the docker container

# docker run -it hello-world

image.png

# docker run -it centos

image.png

Step-11: List the running docker containers

- To List all active containers

# docker ps

image.png

# docker ps -a

image.png

- To list the latest container you created

# docker ps -l

image.png

Step-12: Stop the container

# docker container stop blissful_leavitt

image.png