{"id":7992,"date":"2016-10-12T16:46:45","date_gmt":"2016-10-12T08:46:45","guid":{"rendered":"http:\/\/jpuyy.com\/?p=7992"},"modified":"2020-11-13T12:07:03","modified_gmt":"2020-11-13T04:07:03","slug":"%e8%bf%90%e8%a1%8cdocker%e5%ae%b9%e5%99%a8","status":"publish","type":"post","link":"https:\/\/jpuyy.com\/?p=7992","title":{"rendered":"\u8fd0\u884cdocker\u5bb9\u5668"},"content":{"rendered":"<p>\u8fd0\u884c\u4e00\u4e2a centos \u5bb9\u5668<br \/>\nThe -i and -t flags can be passed to the exec command to keep an interactive shell open, and you can specify the shell you want to attach after the container ID.<\/p>\n<pre>[root@localhost ~]# docker run  -i -t centos \/bin\/bash\r\nUnable to find image 'centos:latest' locally\r\nlatest: Pulling from library\/centos\r\n8d30e94188e7: Pull complete \r\nDigest: sha256:2ae0d2c881c7123870114fb9cc7afabd1e31f9888dac8286884f6cf59373ed9b\r\nStatus: Downloaded newer image for centos:latest\r\n<\/pre>\n<p>\u8fd0\u884c docker \u4ee5 daemon \u65b9\u5f0f\u8fd0\u884c\uff0chost \u5f00\u653e\u7aef\u53e3 5001\uff0c\u5bf9\u5e94\u5bb9\u5668\u5185\u7aef\u53e3 5000<br \/>\nThe -p means &#8220;publish ports&#8221;<\/p>\n<pre>docker run -d -p 5001:5000 python-flask\r\n<\/pre>\n<p>\u67e5\u770b\u4fe1\u606f<\/p>\n<pre>docker info\r\nContainers: 1\r\n Running: 0\r\n Paused: 0\r\n Stopped: 1\r\nImages: 1\r\n<\/pre>\n<p>\u67e5\u770b\u5bb9\u5668\u5217\u8868<\/p>\n<pre>docker ps -a\r\nCONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES\r\nebf5f9bf4bc9        centos              \"\/bin\/bash\"         16 minutes ago      Exited (0) 7 minutes ago                       furious_leakey\r\n<\/pre>\n<p>\u67e5\u770b docker \u8fd0\u884c\u7684 log<\/p>\n<pre>docker logs  furious_leakey<\/pre>\n<p>\u63a2\u6d4b docker \u66f4\u8be6\u5c3d\u4fe1\u606f\uff0cjson \u8f93\u51fa<\/p>\n<pre>docker inspect furious_leakey<\/pre>\n<p>\u9000\u51fa\u540e\u7684\u5bb9\u5668\u662f stopped \u72b6\u6001\uff0c\u73b0\u5728\u6839\u636e\u540d\u5b57 furious_leakey \u542f\u52a8\u5b83<\/p>\n<pre>docker start furious_leakey<\/pre>\n<p>\u901a\u8fc7 shell \u8fdb\u5165\u5230\u5bb9\u5668\u4e2d<\/p>\n<pre>docker attach furious_leakey<\/pre>\n<p>\u4e0a\u9762\u8fd0\u884c\u7684\u5bb9\u5668\u662f\u4ea4\u4e92\u5f0f\u5bb9\u5668<\/p>\n<p>docker\u5de5\u4f5c\u76ee\u5f55\u5728<\/p>\n<pre>\/var\/lib\/docker\/<\/pre>\n<p>\u5bb9\u5668\u5b58\u653e\u5728<\/p>\n<pre>\/var\/lib\/docker\/containers<\/pre>\n<p>\u5220\u9664\u6240\u6709 docker \u5bb9\u5668<\/p>\n<pre>docker rm `docker ps -a -q`<\/pre>\n<p>\u8fdb\u5165\u5230\u8fd0\u884c\u4e2d\u7684 docker<\/p>\n<pre>docker exec -i -t 82d98bdf2d77046ce52a61f2bab27465db868a97faebe94a83581fc0322e4c26 \/bin\/bash<\/pre>\n<p>docker ps \u53ea\u663e\u793a\u5bb9\u5668\u540d<\/p>\n<pre>docker ps -a --format '{{ .Names }}'\r\n<\/pre>\n<p>docker \u53ca\u5bf9\u5e94\u7684\u6240\u6709 ip<\/p>\n<pre>\r\ndocker inspect --format='{{.Name}} - {{range .NetworkSettings.Networks}} {{.IPAddress}} {{end}}' $(docker ps -aq)\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd0\u884c\u4e00\u4e2a centos \u5bb9\u5668 The -i and -t flags can be passed to the exec command to keep an interactive shell open, and you can specify the shell you want to attach after the container ID. [root@localhost ~]# docker run -i -t centos \/bin\/bash Unable to find image &#8216;centos:latest&#8217; locally latest: Pulling from library\/centos 8d30e94188e7: Pull [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[178],"tags":[],"class_list":["post-7992","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/7992","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7992"}],"version-history":[{"count":17,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/7992\/revisions"}],"predecessor-version":[{"id":9184,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/7992\/revisions\/9184"}],"wp:attachment":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7992"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7992"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7992"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}