编程知识 cdmana.com

Docker container is a program. How fresh is it?

Everyone is right Docker Should have a more or less understanding of , I believe we all have a rough understanding from these two pictures Docker And container concept ![](https://img2020.cnblogs.com/blog/1583165/202012/1583165-20201224094233996-1237384383.png) So how can we understand containers more easily `Container` Well ? To put it bluntly ## Container It's a program like us `run` One `mongo` Mapping of `image`![](https://img2020.cnblogs.com/other/1583165/202012/1583165-20201224092457754-588370869.gif) Then we list the containers that are executing with the following command ( The following two commands are equivalent to )```shell# Old order docker ps# New command docker container ls```![](https://img2020.cnblogs.com/other/1583165/202012/1583165-20201224092458028-281846030.png) I personally recommend using the new command > If you have any doubts about the above equivalent order , Or wonder how the automatic completion of commands in the diagram is realized , And why the new command is recommended , Please look at it. [Docker Command auto completion ](https://dayarch.top/p/docker-install-command-completion.html), Before you're familiar with commands , It is suggested to make full use of TAB Key to view the meaning of each command , Then combined with the actual use scenarios , Slowly remember , That's why we run The following command :```shell# top -- Display the running processes of a container ( This is TAB Complete the command prompt instructions given )docker container top mongo```![](https://img2020.cnblogs.com/other/1583165/202012/1583165-20201224092458199-301821934.png) As you can see from the picture above ,PID For 2292,command For `mongod`. Since we say container It's a program , Then we should be in Host You can find it in the library , Execute the following command ```shellps aux | grep mongod``` View execution results :```shellrgyb 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 did `grep mongod` The operation of , There's nothing like that container, Why is this ?![](https://img2020.cnblogs.com/other/1583165/202012/1583165-20201224092458436-1701773837.png) Careful friends may have found that I use Mac The tests we did ,Docker Platform Native execution in Linux On ( stay Linux There will be no such problems in the operating system , You can try it yourself ). I use Docker for Mac, In fact, it is used in macOS Last special xhyve VM In the implementation of small ( Customize )Alpine Linux, So if you want to see this program , We need to get into Mac This Docker VM Execute the following order :```shelldocker run -it --rm --privileged --pid=host justincormack/nsenter1```( I don't want to expand the explanation here , Those who are interested can take a look at this [justincormack/nsenter1 image](https://github.com/justincormack/nsenter1) What has been done ,Docker for Windows You can also enter in this way Docker VM)![](https://img2020.cnblogs.com/other/1583165/202012/1583165-20201224092458727-489543682.png) Come here ,Container It's a program. It's the end of proof , But old gong, What's the use of proving this ?> Programmers have a basic understanding of procedures , Proof Container It's a program , It will be just a “ new ” Take a look at the nature of things , And attached to the content you are familiar with, the program is what resources it can get from the operating system ( Internet / Disk / Files, etc ), When you stop the program , And it will automatically exit , Release resources . therefore , Next, just slowly explore , One Container What resources are used in , How to get resources . Understand these , And I'll gradually understand Docker You can learn from the following two commands Container More details of - `docker container inspect mongo` Look at Container Details of (JSON In the form of information )```shellUsage: docker container inspect [OPTIONS] CONTAINER [CONTAINER...]Display detailed information on one or more containersOptions: -f, --format string Format the output using the given Go template -s, --size Display total file sizes------------------------------docker container inspect mongo```![](https://img2020.cnblogs.com/other/1583165/202012/1583165-20201224092459293-1856300715.png) There are so many details , You can take a simple look at ( There must be information you can read at a glance ), Don't go into it for a moment - `docker container stats mongo` Look at how resources are used ( Dynamic Statistics )```shellUsage: docker container stats [OPTIONS] [CONTAINER...]Display a live stream of container(s) resource usage statisticsOptions: -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```![](https://img2020.cnblogs.com/other/1583165/202012/1583165-20201224092500015-364580394.gif)## To sum up, we have not come up here and we have to learn from each other , Not now , It won't be . But through the actual purpose , Combined with the command to complete the way of self inspection, 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... After each command `--help` Check the usage proof at any time Container It's a program , 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 ?[ Personal blog :https://dayarch.top](https://dayarch.top)[ Add my wechat friends ](https://mp.weixin.qq.com/s/G7BXuZh0Qh1-mE6ts4LJqQ), Group entertainment, learning and communication , Note 「 Into the group 」> ### Welcome to the public account :「 Sun Gong is a soldier 」> - the front Java Technology dry goods sharing > - Summary of efficient tools | Reply 「 Tools 」> - Interview question analysis and answer > - Technical data collection | Reply 「 Information 」> To read detective stories thinking relaxed interesting learning Java Knowledge of technology stack , This book simplifies complex problems , The principle of concretization and graphitization of abstract problems gradually decomposes technical problems , Technology continues to update , Please keep an eye on ......---![](https://img2020.cnblogs.com/other/1583165/202012/1583165-20201224092500802-2081100

版权声明
本文为[itread01]所创,转载请带上原文链接,感谢
https://cdmana.com/2020/12/20201224152743201U.html

Scroll to Top