编程知识 cdmana.com

Docker container is a process. How fresh is it?

Everyone to Docker Should have more or less understanding of , I believe we all have a rough understanding from these two pictures Docker And container concept

So how can we understand containers more easily Container Well ? To put it bluntly

Container It's a process

For example, we run One mongo Mirror image image

Then we list the running containers with the following command ( The following two commands are equivalent to )

#  Old orders 
docker ps
#  New command 
docker container ls

I suggest using the new command

If you have any doubts about the above equivalent order , Or wonder how the automatic completion of the command in the action diagram is realized , And why the new command is recommended , Please have a look at Docker Command auto-complete , Before you're familiar with commands , It is suggested to make full use of TAB Key to see what each command means , And then combined with the actual use scenarios , Slowly memorize , That's deep-rooted

We run The following command :

# top      -- Display the running processes of a container ( This is a  TAB  Complete the instructions given )
docker container top mongo

As you can see from the above figure ,PID by 2292,command by mongod. Since we say container It's a process , Then we should be in Host You can find it in the library , Execute the following command

ps aux | grep mongod

View the execution results :

rgyb           49927   0.0  0.0  4277516    708 s000  S+    4:06PM   0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn mongod

About mongod Only what we just implemented grep mongod The operation of , There's no such thing as that container, Why is that ?

Careful friends may have found that I use Mac Test done ,Docker Platform It runs on Linux On ( stay Linux There will be no such problems in the operating system , You can try it yourself ). I use Docker for Mac, It's actually using macOS Last special xhyve VM A small one running in ( customized )Alpine Linux, So if you want to see this process , We need to get into Mac This Docker VM

Execute the following order :

docker run -it --rm --privileged --pid=host justincormack/nsenter1

( The explanation will not be expanded here , You can have a look at this one justincormack/nsenter1 image What did you do ,Docker for Windows You can also enter in this way Docker VM)

Here we are ,Container It's a process. It's proof , But old gong, What's the use of this ?

Programmers have a basic understanding of processes , prove Container It's a process , It's just a “ new ” Take a look at the essence of things , And attach to what you're familiar with

A process is what resources it can get from the operating system ( The Internet / disk / Documents, etc. ), When the process stops , And it will automatically exit , Release resources . therefore , Next, just slowly explore , One Container What resources are used in , How to get resources . I know that , And I'll gradually understand Docker

You can learn from the following two commands Container More details of

  • docker container inspect mongo see Container Details of (JSON Data form of )
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 mongo

There are so many details , You can take a simple look at ( There must be information you can see at a glance ), There's no need to delve into

  • docker container stats mongo Check the usage of resources ( dynamic database )
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 mongo

summary

If you don't come up here, you'll have to obey the orders , Not now , Not in the future . It's through the actual purpose , Combined with the command to complete the way to check, gradually understand and understand . It is strongly recommended that you complete the installation command , You can make the most of TAB, You can also add --help How to use it at any time

prove Container It's a process , So close to what we already know , The threshold of study is at least half short . Finally, let's play a game , How many commands do you remember in this article ?

The soul asks

  1. Why resource dynamic statistics Mem LIMIT yes 1.941GB, Where is this set up ?
    Personal blog :https://dayarch.top
    Add my wechat friends , Entertainment, learning and communication , remarks 「 Into the group of 」

Welcome to official account :「 Sun Gong is a soldier 」

  • the front Java Technology dry goods sharing
  • Summary of efficient tools | reply 「 Tools 」
  • Interview question analysis and answer
  • Get the technical data | reply 「 Information 」

Study with ease and interest in reading detective stories Java Knowledge of technology stack , In order to simplify complex problems , Abstract problem concretization and graphical principle gradually decompose technical problems , Technology continues to update , Stay tuned ......


版权声明
本文为[RI Gong Yi Bing]所创,转载请带上原文链接,感谢
https://cdmana.com/2020/12/20201224094610864t.html

Scroll to Top