How to play with Docker images on Linux

In our previous article, we have instructed about Docker installation and configuration on Major Linux distribution such as Debian, Ubuntu, LinuxMint, CentOS, RHEL, Fedora, openSUSE, Arch Linux, etc..,. Now, i’m going to play with Docker images & containers. Docker stores downloaded images on the Docker host (local system). By default docker download the images from the Docker Hub Registry which was holding 100000+ images. We can also upload our own Docker images to Docker Hub Registry.

1) Listing images on the Local host

I’m going to check the docker images which is available by default in our local host.
Just fire the below command to list out that.

# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              latest              97434d46f197        2 days ago          188 MB
ubuntu              12.04               8e3c25486445        2 days ago          138.4 MB
hello-world         latest              690ed74de00f        5 months ago        960 B

We can see three crucial pieces of information about our images in the listing.

  • Repository : ubuntuFrom which repository the image came
  • Tag : 12.04The tags for each image
  • Image ID : xxxxThe image ID of each image.

2) Run Docker container

Docker Hub repository holds multiple variants of an image. say for example, ubuntu image having multiple versions like 12.04, 14.04, 14.10, 15.04 & 15.10. Each variant is identified by a tag. so whenever we run docker better to use image:tag so that we can run the specific one. If you don’t specify a variant, by default Docker will use latest version of image. Here i’m going to run CentOS image.

# docker run -ti ubuntu:12.04 /bin/bash
root@0182f4f65333:/# cat /etc/*-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04.5 LTS"
NAME="Ubuntu"
VERSION="12.04.5 LTS, Precise Pangolin"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu precise (12.04.5 LTS)"
VERSION_ID="12.04"

3) Search Docker images

By default docker download the images from the Docker Hub Registry which was holding 100000+ images. Lot of people have created Docker images for a variety of purposes and uploaded to Docker Hub. If we want any images, we have option to search the image. Once we finalized the image we can download it from Docker Hub Registry to Docker host (local system).

# docker search centos
NAME                            DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
centos                          The official build of CentOS.                   2040      [OK]       
jdeathe/centos-ssh              CentOS-6 6.7 x86_64 / CentOS-7 7.2.1511 x8...   17                   [OK]
jdeathe/centos-ssh-apache-php   CentOS-6 6.7 x86_64 / Apache / PHP / PHP M...   14                   [OK]
million12/centos-supervisor     Base CentOS-7 with supervisord launcher, h...   9                    [OK]
blalor/centos                   Bare-bones base CentOS 6.5 image                8                    [OK]
nimmis/java-centos              This is docker images of CentOS 7 with dif...   8                    [OK]
torusware/speedus-centos        Always updated official CentOS docker imag...   7                    [OK]
nickistre/centos-lamp           LAMP on centos setup                            3                    [OK]
nathonfowlie/centos-jre         Latest CentOS image with the JRE pre-insta...   3                    [OK]

4) Download Docker images

By default docker will download the images which isn’t present on the Docker host (local system) when we are run the docker container which will take some time to launch the container. So better we can finalize the necessary container then download to Docker host (local system) before Run Docker container.

# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
a3ed95caeb02: Pull complete 
196355c4b639: Pull complete 
Digest: sha256:381f21e4c7b3724c6f420b2bcfa6e13e47ed155192869a2a04fa10f944c78476
Status: Downloaded newer image for centos:latest

# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              latest              97434d46f197        2 days ago          188 MB
ubuntu              12.04               8e3c25486445        2 days ago          138.4 MB
centos              latest              d0e7f81ca65c        2 weeks ago         196.6 MB
hello-world         latest              690ed74de00f        5 months ago        960 B

[To pull specific image]
# docker pull centos:6.7

5) Download user Docker images

The similar way we can pull the user image belongs to a member of the Docker community but the image is slightly different compare with Docker Hub images. You can identify user images as they are always prefixed with the user name like xxx/xxxx.

# docker pull xxx/xxxx

6) Remove an image from the host

We can easily remove the Docker image from host which we don’t need it anymore.

# docker rmi debian

Enjoy…)

About Magesh Maruthamuthu

Love to play with all Linux distribution

View all posts by Magesh Maruthamuthu

Leave a Reply

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