Install and Use Docker on CentOS 7

Docker is an application used to manage application processes in containers. Containers run applications in resource-isolated process. By using docker you can build, test and deploy applications that can run anywhere as portable and self-sufficient containers. In this tutorial, you are going to learn how to install and use Docker on CentOS 7.

Prerequisites

Before you start to install Docker on CentOS 7. You must have the root user account credentials of your system.

Install Docker on CentOS

Here we will install Docker on CentOS from Latest Docker’s Repository. Follow the steps below to install Docker on CentOS.

Update the system and install required dependencies typing following command:

Executing the Docker Command Without Sudo

By default, docker command can only run by sudo user or member of docker group which created while installing Docker. If you want to run docker command without sudo then you should add the user to docker group.

If you are already logged in then to add the user to docker group run below command:

sudo usermod -aG docker $USER

How to Use Docker Command

Following is the basic syntax for docker command:

docker [option] [subcommand] [arguments]

List all the available subcommands typing following command:

docker

Get help for any docker subcommand using the following command:

docker docker-subcommand --help

Working with Docker Images

Docker containers are built from Docker Images and these images are pulled from Docker Hub which is a registry managed by Docker Company. On the Docker Hub, anyone can host their images, because of this most of the app images and Linux distro’s are already available on Docker Hub.

Search Docker Images

You can search for an image on Docker Hub by using docker command with search sub-command.

List Downloaded Docker Images

Remove Docker Images

If you want to remove downloaded docker image then you can do so by using the following command. Below command will remove CentOS image from your system.

docker image rm centos

Working with Docker Containers

Docker container is an instance of Docker Image. You can also interact with the container. Containers are the resource-friendly virtual machines. By using docker container command we can manage operations on a container.

Start a Container

By using container run subcommand you can run a container which is an instance of the image. If the container image is not available then it will first download and then the container will be started.

To start the container of CentOS you should run below command:

docker container run centos

In the above command, we didn’t provide any command to execute after starting CentOS container so it will boot then executes the empty command and then exits.

To interact with CentOS container after booting up, use -it switch. To do so run below command: