Getting Familiar With Docker Commands Docker Terms: Docker – Part 3 A

In the tutorial, we will get familiar with Docker terms and their terminology. Here I have compiled almost every command used in Docker and its implementation

Just in case, if  you did miss Previous two tutorial regarding Docker can be read here:

Part 1: What Is Docker And Concept Of Containers With Virtualization?
Part 2: How To Install Docker On CentOS/RHEL 6/7? And Learn Docker HUB Registration
Part 3B: Getting Familiar With Docker Commands Docker Terms: Docker – Part 3 B
Part 4: How To Perform Task Like Install, Run And Delete Applications Inside Docker Containers

So Let’s dig out Command in Docker

In Docker, everything is based on Images. An image is a combination of a file system and parameters. So most of our command will move around images.

Command 1: Create an Instance of Container

This command is used to create an instance of a container from an image.

#docker run hello-world
  • The Docker command tells the Docker program on the Operating System that something needs to be done.
  • The run command is used to mention that we want to create an instance of an image, called a container.
  •  “hello-world” represents the image from which the container is made.




Command 2: Docker Information

This Command will show all the detailed information.

[root@localhost ~]# docker info

 

Containers: 3
Running: 0
Paused: 0
Stopped: 3
Images: 1
Server Version: 1.12.6
Storage Driver: devicemapper
.................................................................
.............................................................
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Insecure Registries:
 127.0.0.0/8
Registries: docker.io (secure)

Command 3: Docker Version

This command will help you to check out the running version of Docker of client end and server end.

[root@localhost ~]# docker version 
Client:
 Version: 1.12.6
 API version: 1.24
 Package version: docker-1.12.6-28.git1398f24.el7.centos.x86_64
 Go version: go1.7.4
 Git commit: 1398f24/1.12.6
 Built: Fri May 26 17:28:18 2017
 OS/Arch: linux/amd64

Server:
 Version: 1.12.6
 API version: 1.24
 Package version: docker-1.12.6-28.git1398f24.el7.centos.x86_64
 Go version: go1.7.4
 Git commit: 1398f24/1.12.6
 Built: Fri May 26 17:28:18 2017
 OS/Arch: linux/amd64

Comand 4: List Docker Commands

To get a list of all the command that works on docker on the console, you may hit below command on terminal. All the command and arguments will get populated on the terminal.

[root@localhost ~]# docker

Note: You Cab Use Run ‘docker COMMAND –help‘ for more information on a command

Command 5: Login Docker HUB or Docker Registry

Docker Registry or Docker HUB is used for searching and pulling Docker images(like CentOs, Ubuntu etc.) from the Docker HUB. Also, you can push and update your images to Docker HUB for future use and there are other many things you can do with Docker HUB.

You need an account on Docker HUB to get logged in. If you don’t have an account you can learn it from Part 2. Following is the Command to Login into Docker HUB or Docker Registry:

[root@localhost ~]# docker login
Username: <Your Docker Login Username>
Password: <Type In Your Password>
Login succeeded.

Command 5: To Seach Images With Doker HUB

Soon After logging into Docker HUB, you are eligible for PULL, PUSH, Search, Update docker image from Docker HUB. These images can be used for creating containers. Docker Hub has lots of community free images created for you like Ubuntu image mongo image and a much more great deal of free images from its repositories. The following command is used to search centOS images from the repository.

[root@localhost ~]# docker search centos
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/centos The official build of CentOS. 3432 [OK] 
docker.io docker.io/jdeathe/centos-ssh CentOS-6 6.9 x86_64 / CentOS-7 7.3.1611 x8... 74 [OK]
docker.io docker.io/nimmis/java-centos This is docker images of CentOS 7 with dif... 26 [OK]
docker.io docker.io/gluster/gluster-centos Official GlusterFS Image [ CentOS-7 + Glu... 19 [OK]
docker.io docker.io/kinogmt/centos-ssh CentOS with SSH 15 [OK]
docker.io docker.io/egyptianbman/docker-centos-nginx-php A simple and highly configurable docker co... 9 [OK]




Command 6: Download Docker image

After logging in and searching out images from docker you can pull these image i=on yu local system using the following command.

[root@localhost ~]#docker pull centos
Using default tag: latest
Trying to pull repository docker.io/library/centos ... 
latest: Pulling from docker.io/library/centos
d5e46245fe40: Pull complete 
Digest: sha256:aebf12af704307dfa0079b3babdca8d7e8ff6564696882bcb5d11f1d461f9ee9

Command 7: List Docker Images On Local System

Now when you have lots of downloaded docker images you can look at all the docker images present on your local system by the following command.

[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/hello-world latest 1815c82652c0 13 days ago 1.84 kB
docker.io/centos latest 3bee3060bfc8 3 weeks ago 192.5 MB

TAG − This is used to logically tag images.
Image ID − This is used to uniquely identify the image.
Created − The number of days since the image was created.
Virtual Size − The size of the image.

Command 8: Remove Docker Image

When you have lots of running which are obsolete or you no longer need any Docker image then you can remove that image using the following command.

Syntex: docker rmi ImageName

[root@localhost ~]# docker rmi ubuntu
Untagged: ubuntu:latest
Untagged: docker.io/ubuntu@sha256:a0ee7647e24c8494f1cf6b94f1a3cd127f423268293c25d924fbe18fd82db5a4
Deleted: sha256:d355ed3537e94e76389fd78b77241eeba58a11b8faa501594bc82d723eb1c7f2
Deleted: sha256:dd864b96a38e849779c42a04159bbb39c7ab47253bf222049b471d8f26b60d14
Deleted: sha256:80e85c818fa0447c96a42501ca7457ad83e5834aa76f22c366342106889b7411
Deleted: sha256:11a2a269cf6ec2cefcb4e24370b8b2d7a4875450bafd3a70bd42eb787481d798
Deleted: sha256:1118f33a0ee7a874a04318248a886b2bdaf44cba286644ab7ded870aefe64b62
Deleted: sha256:cb11ba6054003d39da5c681006ea346e04fb3444086331176bf57255f149c670

Command 9: Run A Docker Container

The concept is a little catchy, whenever a command is sent for execution in the Docker Image, a container is obtained. When this command execution is finished,  the container gets stopped (a non-running or exited container state). It Means at every command execution into the same image a new container is created again and again and exited.

All these created containers remain on the host filesystem. You can delete them by using the docker rm command. To run or create a container using the following command:

Syntex: docker run [local image] [command to run into container]

[root@localhost ~]# docker run centos cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)

Command 10: List Running Docker Containers

Whenever a command execution is performed on a Docker Image a container is created and gets stopped after execution but it remains in an exited or non-running state. The following command will display a list of the running and stopped (non-running) containers:

[root@localhost ~]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a636b6753136 centos "cat /etc/redhat-rele" 5 minutes ago Exited (0) 4 minutes ago hungry_mayer

Note: ContainerID will be used in many actions. This command also gives you information like CONTAINER ID, IMAGE, COMMAND, CREATED, STATUS, PORTS, NAMES.

Command 11: Start A Container

Now We have a ContainerID so we can start the container again with the command that was used to create it, by using the following command

Syntex: docker start ContainerID

[root@localhost ~]# docker start a636b6753136
a636b6753136

Command 12: Listing of Containers (Expended)

In a production environment there are many running containers and to list them we have command. This command is used to get the currently running containers.

[root@localhost home]# docker ps

 

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7e0cab13b5f3 centos "/bin/sh" 12 seconds ago Up 5 seconds sleepy_wing

This Can also be used with the ‘-a’ argument and this command will list all of the containers on the system

[root@localhost home]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7e0cab13b5f3 centos "/bin/sh" 43 seconds ago Up 35 seconds sleepy_wing
05bd33e0b71e centos "/bin/sh" 3 hours ago Exited (0) 3 hours ago tiny_swartz
2b8b51d81869 centos "/bin/sh" 3 hours ago Exited (0) 3 hours ago infallible_bhaskara

Continue Reading With PART 3B and learn more commands to complete this tutorial.




Read More:

Part 1: What Is Docker And Concept Of Containers With Virtualization?
Part 2: How To Install Docker On CentOS/RHEL 6/7? And Learn Docker HUB Registration
Part 3A: Getting Familiar With Docker Commands Docker Terms: Docker – Part 3 A
Part 3B: Getting Familiar With Docker Commands Docker Terms: Docker – Part 3 B
Part 4: How To Perform Task Like Install, Run And Delete Applications Inside Docker Containers