In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article focuses on "sharing common commands in Docker". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "Docker common command sharing"!
In addition to the basic docker pull, docker image, and docker ps, there are also some commands and parameters that are important to write down here to avoid forgetting.
Environmental information
The following is the environment for this operation:
Operating system: CentOS Linux release 7.7.1908
Docker:19.03.2
Suppose the current environment is running with two containers, and the following operations are based on these two containers:
[root@vostro harbor] # docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES11548ac31116 tomcat:9.0.26-jdk8-openjdk "catalina.sh run" 6 seconds ago Up 5 seconds 8080/tcp inspiring_ardinghelli21c0499ccc76 nginx "nginx-g'daemon of..." 29 minutes ago Up 29 minutes 80/tcp strange_zhukovsky overall information
Docker info is used to view the overall information:
[root@vostro harbor] # docker infoClient: Debug Mode: falseServer: Containers: 0 Running: 0 Paused: 0 Stopped: 0 Images: 19 Server Version: 19.03.2 Storage Driver: overlay Backing Filesystem: xfs Supports d_type: true... Free up space
Docker system prune deletes the following: a. A container that has stopped; b. An unused network; c. All untagged images; d. Cache generated when building an image; note: this command deletes too many things, so use it with caution
Delete the stopped container: docker container prune
Delete unused networks: docker network prune
Delete a mirror without Tag: docker image prune
Delete an image without a container: docker image prune-a
Delete unused data volumes: docker volume prune
Filter
When executing docker ps, all the containers in running status are listed. Sometimes we only want to see what we are concerned about, so we can filter the results:
Filter by container ID: docker ps-f id=11548ac31116
[root@vostro harbor] # docker ps-f id=11548ac31116CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES11548ac31116 tomcat:9.0.26-jdk8-openjdk "catalina.sh run" 4 minutes ago Up 4 minutes 8080/tcp inspiring_ardinghelli
Filter by container name: docker ps-f name=inspiring_ardinghelli
[root@vostro harbor] # docker ps-f name=inspiring_ardinghelliCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES11548ac31116 tomcat:9.0.26-jdk8-openjdk "catalina.sh run" 7 minutes ago Up 7 minutes 8080/tcp inspiring_ardinghelli
By image filtering, there are three subdivisions of this filter: a. Filter by image name and TAG: docker ps-f ancestor=tomcat:9.0.26-jdk8-openjdk b. Filter by mirror ID: docker ps-f ancestor=4965bfab1881 c. Filter by image summary information: docker ps-f ancestor=tomcat@sha256:67a9904e3ceb03abc50db7b374db7362f7e44d08a41488dd24c2bb14df8989a3
How to obtain the summary information of the image? Execute the command docker inspect tomcat:9.0.26-jdk8-openjdk to get the details of the image, as shown in the following figure. The summary information is in the red box:
Filter by container status: docker ps-f status=running. The states are: created, restarting, running, removing, paused, exited, dead
There are other filtering conditions, but they are not often used, such as the following figure:
Information acquisition
Check the hard disk space occupied by the container: the container resource occupancy is shown in the red box on docker ps-s. 508MB says: image size + container size, and 40KB represents the resource occupied by the container itself.
Only look at certain fields when viewing container information, for example, only look at the container ID, image, and container name: docker ps-- format "table {{.ID}}: {{.Image}}: {{.Names}}"
[root@vostro harbor] # docker ps-- format "table {{.ID}}: {{.Image}}: {{.Names}}" CONTAINER ID: IMAGE: NAMES11548ac31116: tomcat:9.0.26-jdk8-openjdk: inspiring_ardinghelli21c0499ccc76: nginx: strange_zhukovsky
The following figure shows the names of all the columns: 3. As shown in the red box below, when the field content is too long, it shows part of the content. If you want to see the complete information, please use docker ps-- no-trunc 4. When you use the docker history command to view the construction information of the image, it will also be omitted because the content is too long, as shown in the following figure. You can also use the-- no-trunc parameter to see the omitted information:
Combined use
Only the ID field of the Tomcat container is displayed: docker ps-f ancestor=tomcat:9.0.26-jdk8-openjdk-Q
[root@vostro harbor] # docker ps-f ancestor=tomcat:9.0.26-jdk8-openjdk-q11548ac31116
The above command gets the ID field of the Tomcat container. If we want to stop the container, combine the above command with docker stop: docker stop $(docker ps-f ancestor=tomcat:9.0.26-jdk8-openjdk-Q)
[root@vostro harbor] # docker stop $(docker ps-f ancestor=tomcat:9.0.26-jdk8-openjdk-Q) 11548ac31116 [root@vostro harbor] # docker ps-aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES11548ac31116 tomcat:9.0.26-jdk8-openjdk "catalina.sh run" About An hour ago Exited 43 seconds ago inspiring_ardinghelli21c0499ccc76 nginx "nginx-g'daemon of..." 2 hours ago Up 2 hours 80/tcp strange_zhukovsky
You can see that the tomcat container has stopped.
At this point, I believe you have a deeper understanding of "Docker common command sharing". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.