Tuesday, 26 November 2019

How to pull and run Docker images in CentOS 7

Docker containers are built from Docker images which can be downloaded from Docker Hub. Docker Hub is a cloud-based registry contains Docker images either in a public or private repository.

This article describes How to pull and run Docker images on CentOS7.

Step 1. Searching Docker Images: To search Docker images just run Docker sub command Docker search <image_name> as shown below:

[root@linuxcnf ~]# docker search centos
INDEX       NAME                                         DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/centos                             The official build of CentOS.                   5694      [OK]
docker.io   docker.io/ansible/centos7-ansible            Ansible on Centos7                              126                  [OK]
docker.io   docker.io/pivotaldata/centos7-dev            CentosOS 7 image for GPDB development           0
docker.io   docker.io/smartentry/centos                  centos with smartentry                          0                    [OK]
[root@linuxcnf ~]#

Step 2. Download Image: Run the following Docker sub command pull to download appropriate image from Docker official repository:

[root@linuxcnf ~]# docker image pull centos
Using default tag: latest
Trying to pull repository docker.io/library/centos ...
latest: Pulling from docker.io/library/centos
729ec3a6ada3: Pull complete
Digest: sha256:f94c1d992c193b3dc09e297ffd54d8a4f1dc946c37cbeceb26d35ce1647f88d9
Status: Downloaded newer image for docker.io/centos:latest
[root@linuxcnf ~]#

Step 3. Verify Downloaded Image: Once the image is downloaded, run the following command to verify the downloaded image:

[root@linuxcnf ~]# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/centos    latest              0f3e07c0138f        7 weeks ago         220 MB
[root@linuxcnf ~]#

Step 4. Run the Docker Image: Run the downloaded Docker image by executing Docker sub command Docker container:

[root@linuxcnf ~]# docker container run -it centos /bin/bash
[root@c0860928ec75 /]#

[root@c0860928ec75 /]# cat /etc/centos-release
CentOS Linux release 8.0.1905 (Core)
[root@c0860928ec75 /]# exit
[root@linuxcnf ~]#

Done!!! Docker image pulled and executed successfully and entered into interactive bash shell for use.

No comments:

Post a comment