Everyone should have more or less understanding of Docker. I believe that everyone has a rough understanding of Docker and container concepts from these two pictures
How can we understand containers more easily? To put it bluntly
Container is a process
Let’s say we run a mongo image
We then list the running containers with the following command (the two commands are equivalent)
#The old command
docker ps
#A new command
docker container ls
Copy the code
I recommend using the new command
If you have doubts for the equivalent command, or curious commands in the diagram is how to realize automatic completion, and why it is recommended to use the new order, please see the Docker command automatic completion, before is not familiar with the command, make full use of the TAB key to see the meaning of each command, and then combined with the actual usage scenarios, memory slowly, It’s ingrained
We run the following command:
#Top -- Display the running processes of a container
docker container top mongo
Copy the code
As can be seen from the figure above, PID is 2292 and command is Mongod. Since we say that container is a process, we should find it in Host and execute the following command
ps aux | grep mongod
Copy the code
View the execution result:
Rgyb 49927 0.0 0.0 4277516 708 s000 S+ 4:06pm 00:00.00 grep --color=auto -- excide-dir =.bzr -- excide-dir =CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn mongodCopy the code
About Mongod, there is only the operation of grep Mongod we just performed, but there is no container mentioned above. Why is this?
Careful friends may have noticed from the GIF that I am using Mac to do the test, Docker Platform runs on Linux (Linux operating system does not have the above problem, you can try by yourself). I’m using Docker for Mac, actually using a small (custom)Alpine Linux running in a special Xhyve VM on macOS, so to see this process we need to go into the Docker VM for Mac
Run the following command:
docker run -it --rm --privileged --pid=host justincormack/nsenter1
Copy the code
Docker for Windows can also use this method to access the Docker VM.
So far, the Container is a process, but what’s the point of proving that, Gong?
Programmers have a basic understanding of processes, and proving that a Container is a process is just a matter of peeling something “new” down to its essentials and attaching it to something you’re familiar with
A process refers to the resources (network, disk, files, etc.) that it can obtain from the operating system. When a process is stopped, it automatically exits and releases the corresponding resources. So, slowly explore what resources are used in a Container and how they are obtained. Knowing that, you know what Docker is
You can run the following two commands to learn more about containers
docker container inspect mongo
Viewing Container details (as JSON data)
Usage: docker container inspect [OPTIONS] CONTAINER [CONTAINER...] Display detailed information on one or more containers Options: -f, --format string Format the output using the given Go template -s, --size Display total file sizes ------------------------------ docker container inspect mongoCopy the code
There are so many details that you can simply take a look at them (there must be some information that you can understand at a glance) without digging too deeply
docker container stats mongo
Viewing resource Usage (Dynamic Statistics)
Usage: docker container stats [OPTIONS] [CONTAINER...] Display a live stream of container(s) resource usage statistics Options: -a, --all Show all containers (default shows just running) --format string Pretty-print images using a Go template --no-stream Disable streaming stats and only pull the first result --no-trunc Do not truncate output ---------------------------- docker container stats mongoCopy the code
conclusion
Not now, not in the future. But through the practical purpose, combined with the command to complete the way of self-view gradually understanding and understanding. It is highly recommended that you install command completion. You can use TAB as much as you like, or you can add –help after each command to see how it is used at any time
Proving that Container is a process is at least half the barrier to learning that we already have. Finally, let’s play a game. How many of these commands have you memorized?
Soul asking
- Why is Mem LIMIT 1.941GB? Where is this set?
Personal blog: https://dayarch.top
Day arch a soldier | original