Some Basic Docker Commands Beginner Should Know
Docker is a container-based application framework that allows deploying programs that are run as containers. Docker Containers are generally used in CI/CD (Continuous Integration/Continuous Deployment) platform. There are several docker commands you must know when working with Docker.
Useful Articles:
- WHAT IS DOCKER & DOCKER CONTAINER ?
- HOW TO INSTALL DOCKER ENGINE ON UBUNTU 19.10/18.04
- HOW TO INSTALL DOCKER ENGINE ON CENTOS/RHEL 8
- HOW TO INSTALL DOCKER ON UBUNTU 18.04 & 16.04 LTS
- HOW TO INSTALL DOCKER CE ON CENTOS/RHEL 7/6
- WHAT IS DOCKERFILE AND BASICS OF DOCKERFILE
- INSTALLATION OF DOCKER FAILS ON CENTOS 8 WITH ERROR – PACKAGE CONTAINERD.IO-1.2.10-3.2.EL7.X86_64 IS EXCLUDED
In this tutorial, we will help you to understand some basic Docker commands.
Search Docker Images
We can search the Docker images in Docker Hub. Let’s assume you want to find CentOS images.
# docker search centos
Download Docker Container Images
Once you find the image you can pull the image to the local system from Docker hub. Docker pull is almost the same as git pull.
# docker pull centos
Using default tag: latest latest: Pulling from library/centos 8a29a15cefae: Pull complete Digest: sha256:fe8d824220415eed5477b63addf40fb06c3b049404242b31982106ac204f6700 Status: Downloaded newer image for centos:latest docker.io/library/centos:latest
View all Downloaded Docker Container Images
Whenever we download the docker images in your local system using pull command and it saves the docker image locally at /var/lib/docker location. To list all the docker images pulled on the system use following command.
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu latest 1d622ef86b13 12 days ago 73.9MB nginx latest 602e111c06b6 12 days ago 127MB httpd latest b2c2ab6dcf2e 12 days ago 166MB centos latest 470671670cac 3 months ago 237MB hello-world latest bf756fb1ae65 4 months ago 13.3kB docker/whalesay latest 6b362a9f73eb 4 years ago 247MB
Run a Docker Container
Use the following command to run the downloaded Docker image.
# docker run –it centos
-it: It will open a shell that can be used to interact with the container.
Run a Docker Container in Detach Mode
We can launch a container in detached mode using –d option using the following command.
# docker run –d centos
List Container
We can list all the running containers using the following command.
# docker ps
List Container including Shutdown State
To List all the containers including shutdown using the following command.
# docker ps -a
Getting Container Console
If Docker container is running in detach mode and need to take the console of the container using the following command.
# docker attach priceless_austin
Start, Stop, Restart and Kill Containers
We can start, stop and restart docker containers.
Start the container using mention command.
# docker start priceless_austin
Stop the container using mention command.
# docker stop priceless_austin
Restart the container using mention command.
# docker restart priceless_austin
Kill the container using mention command.
# docker kill priceless_austin
Delete/Remove Containers
Remove the Docker containers using the container id or container name. Containers will only remove when docker is in a stopped state.
# docker rm 0fb1de712c0d
To remove a running container forcefully, use ‘-f’ option
# docker rm -f f529d03c4692
Delete/Remove Docker Containers Images
Not like containers you can remove the container images also. You can use image name and id to remove the images. Use the mentioned command to remove the container images.
# docker rmi nginx
Display History of Docker Image
History of Docker command will display the list of commands used while building docker images.
# docker history httpd
Containers resource usage statistics
Display CPU, memory, and network I/O usage of all the containers using the following command. Below command will live to show live streaming of resource usage.
# docker stats
Display statistics without live streaming.
# docker stats --no-stream
Reference: https://docs.docker.com/engine/reference/commandline/docker/
Enjoy it!
wow, great, I was wondering how to cure acne naturally. and found your site by google, learned a lot, now I’m a bit clear. I’ve bookmarked your site and also add RSS. keep us updated
It’s glad to hear that my blog has cleared your doubts.
Awesome blog. I enjoyed reading your articles. This is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work!
stunning, incredible, I was thinking about how to fix skin inflammation normally.I’ve bookmark your site and furthermore include rss. keep us refreshed.
First You got a great blog. I will be interested in more similar topics. I see you got really very useful topics, I will be always checking your blog thanks.
Quite right! It is good idea. I support you.
Nice one and such a useful post.
Found good information on your webpage as well as supposing such type of thought in the years to come as it is extremely beneficial as well as instructive.