{"id":1964,"date":"2021-01-29T14:04:52","date_gmt":"2021-01-29T06:04:52","guid":{"rendered":"https:\/\/www.yusian.com\/blog\/?p=1964"},"modified":"2021-01-29T16:57:58","modified_gmt":"2021-01-29T08:57:58","slug":"docker%e5%b8%b8%e7%94%a8%e5%91%bd%e4%bb%a4%e6%b1%87%e6%80%bb","status":"publish","type":"post","link":"https:\/\/www.yusian.com\/blog\/devops\/2021\/01\/29\/1404521964.html","title":{"rendered":"Docker\u5e38\u7528\u547d\u4ee4\u6c47\u603b"},"content":{"rendered":"<ol>\n<li>\u641c\u7d22\u955c\u50cf\n<pre><code class=\"language-shell line-numbers\">$ docker search centos\nNAME                               DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED\ncentos                             The official build of CentOS.                   6385      [OK]       \nansible\/centos7-ansible            Ansible on Centos7                              132                  [OK]\nconsol\/centos-xfce-vnc             Centos container with \"headless\" VNC session\u2026   125                  [OK]\njdeathe\/centos-ssh                 OpenSSH \/ Supervisor \/ EPEL\/IUS\/SCL Repos - \u2026   117                  [OK]\ncentos\/systemd                     systemd enabled base container.                 93                   [OK]\ncentos\/mysql-57-centos7            MySQL 5.7 SQL database server                   87                   \nimagine10255\/centos6-lnmp-php56    centos6-lnmp-php56                              58                   [OK]\ntutum\/centos                       Simple CentOS docker image with SSH access      46                   \nkinogmt\/centos-ssh                 CentOS with SSH                                 29                   [OK]\npivotaldata\/centos-gpdb-dev        CentOS image for GPDB development. Tag names\u2026   13                   \nguyton\/centos6                     From official centos6 container with full up\u2026   10                   [OK]\nnathonfowlie\/centos-jre            Latest CentOS image with the JRE pre-install\u2026   8                    [OK]\ncentos\/tools                       Docker image that has systems administration\u2026   7                    [OK]\ndrecom\/centos-ruby                 centos ruby                                     6                    [OK]\npivotaldata\/centos                 Base centos, freshened up a little with a Do\u2026   5                    \npivotaldata\/centos-gcc-toolchain   CentOS with a toolchain, but unaffiliated wi\u2026   3                    \ndarksheer\/centos                   Base Centos Image -- Updated hourly             3                    [OK]\npivotaldata\/centos-mingw           Using the mingw toolchain to cross-compile t\u2026   3                    \nmamohr\/centos-java                 Oracle Java 8 Docker image based on Centos 7    3                    [OK]\nindigo\/centos-maven                Vanilla CentOS 7 with Oracle Java Developmen\u2026   1                    [OK]\nblacklabelops\/centos               CentOS Base Image! Built and Updates Daily!     1                    [OK]\nmcnaughton\/centos-base             centos base image                               1                    [OK]\npivotaldata\/centos7-dev            CentosOS 7 image for GPDB development           0                    \npivotaldata\/centos6.8-dev          CentosOS 6.8 image for GPDB development         0                    \nsmartentry\/centos                  centos with smartentry                          0                    [OK]\n<\/code><\/pre>\n<\/li>\n<li>\u62c9\u53d6\u955c\u50cf\n<pre><code class=\"language-shell line-numbers\">$ docker pull nginx\nUsing default tag: latest\nlatest: Pulling from library\/nginx\na076a628af6f: Already exists \n0732ab25fa22: Pull complete \nd7f36f6fe38f: Pull complete \nf72584a26f32: Pull complete \n7125e4df9063: Pull complete \nDigest: sha256:10b8cc432d56da8b61b070f4c7d2543a9ed17c2b23010b43af434fd40e2ca4aa\nStatus: Downloaded newer image for nginx:latest\ndocker.io\/library\/nginx:latest\n<\/code><\/pre>\n<\/li>\n<li>\u67e5\u770b\u955c\u50cf\n<pre><code class=\"language-shell line-numbers\">$ docker images\nREPOSITORY   TAG       IMAGE ID       CREATED       SIZE\nmysql        5.7       a70d36bc331a   9 days ago    449MB\nnginx        latest    f6d0b4767a6c   2 weeks ago   133MB\ncentos       latest    300e315adb2f   7 weeks ago   209MB\n<\/code><\/pre>\n<\/li>\n<li>\u5220\u9664\u955c\u50cf\n<pre><code class=\"language-shell line-numbers\">$ docker rmi centos\nUntagged: centos:latest\nUntagged: centos@sha256:5528e8b1b1719d34604c87e11dcd1c0a20bedf46e83b5632cdeac91b8c04efc1\nDeleted: sha256:300e315adb2f96afe5f0b2780b87f28ae95231fe3bdd1e16b9ba606307728f55\nDeleted: sha256:2653d992f4ef2bfd27f94db643815aa567240c37732cae1405ad1c1309ee9859\n<\/code><\/pre>\n<\/li>\n<li>\u521b\u5efa\u5bb9\u5668\n<pre><code class=\"language-shell line-numbers\">$ docker create -it centos\n0d320f497f02db0577174b95926659bcd6ccb6d58ed7ae8d96439465012f4742\n$ docker ps -a\nCONTAINER ID   IMAGE       COMMAND                  CREATED          STATUS          PORTS                 NAMES\n0d320f497f02   centos      \"bash\"                   10 seconds ago   Created                               sleepy_babbage\n<\/code><\/pre>\n<\/li>\n<li>\u67e5\u770b\u5bb9\u5668\n<pre><code class=\"language-shell line-numbers\"># \u67e5\u770b\u5f53\u524d\u6b63\u5728\u8fd0\u884c\u7684\u5bb9\u5668\n$ docker ps\nCONTAINER ID   IMAGE       COMMAND                  CREATED          STATUS          PORTS                 NAMES\ne3266aa82bfa   mysql:5.7   \"docker-entrypoint.s\u2026\"   10 minutes ago   Up 10 minutes   3306\/tcp, 33060\/tcp   charming_euler\n\n# \u67e5\u770b\u6240\u6709\u5bb9\u5668\n$ docker ps -a\nCONTAINER ID   IMAGE       COMMAND                  CREATED          STATUS          PORTS                 NAMES\ne3266aa82bfa   mysql:5.7   \"docker-entrypoint.s\u2026\"   10 minutes ago   Up 10 minutes   3306\/tcp, 33060\/tcp   charming_euler\n<\/code><\/pre>\n<\/li>\n<li>\u542f\u52a8\u5bb9\u5668\n<pre><code class=\"language-shell line-numbers\"># \u901a\u8fc7id\u6216\u540d\u79f0\u6765\u64cd\u4f5c\n$ docker start 0d320f497f02\n0d320f497f02\n<\/code><\/pre>\n<\/li>\n<li>\u8fdb\u5165\u5bb9\u5668(exec\u4e0eattach\u7684\u533a\u522b)<\/p>\n<\/li>\n<\/ol>\n<ul>\n<li><code>exec<\/code>\u662f\u6267\u884c\u547d\u4ee4\u7684\u610f\u601d\uff0c\u5c31\u662f\u5728\u5f53\u524d\u5bbf\u4e3b\u673a\u4e0a\u6267\u884c\u5bb9\u5668\u4e2d\u7684\u547d\u4ee4\uff0c\u901a\u8fc7-it\u7684\u53c2\u6570\u53ef\u4ee5\u8f93\u5165\u4e0e\u8f93\u51fa\uff0c\u6267\u884cbash\u547d\u4ee4\u5c31\u662f\u5176\u4e2d\u7684\u4e00\u79cd\uff0c\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u6253\u5f00\u4e00\u4e2a\u7ec8\u7aef\uff0c\u6b64\u65f6\u5bbf\u4e3b\u4e3b\u673a\u5f53\u524d\u7684\u7ec8\u7aef\u88ab\u5bb9\u5668\u5185\u7684\u7ec8\u7aef\u6240\u8986\u76d6\uff0c\u6240\u4ee5\u7684\u64cd\u4f5c\u90fd\u4f1a\u88ab\u5bb9\u5668\u63a5\u7ba1<\/li>\n<li>\n<p><code>attach<\/code>\uff1aAttach local standard input, output, and error streams to a running container\uff0c\u610f\u601d\u662f\u8ddf\u8e2a\u5bb9\u5668\u5185\u7684\u8f93\u5165\u4e0e\u8f93\u51fa\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u679c\u591a\u4e2a\u7ec8\u7aef\u540c\u65f6attach\u5230\u4e00\u4e2a\u5bb9\u5668\uff0c\u5927\u5bb6\u7684\u53ef\u4ee5\u770b\u5230\u76f8\u540c\u7684\u754c\u9762\uff0c\u6211\u80fd\u770b\u5230\u4f60\u8f93\u5165\u7684\uff0c\u4f60\u4e5f\u80fd\u770b\u5230\u6211\u8f93\u51fa\u7684\uff0c\u540c\u6b65\u3002<\/p>\n<pre><code class=\"language-shell line-numbers\"># \u901a\u8fc7Docker\u6267\u884c\u811a\u672c\u7684\u65b9\u5f0f\u6253\u5f00\u5bb9\u5668\u5185\u7684\u7ec8\u7aef\n$ docker exec -it 582eb515c4ee bash\n[root@582eb515c4ee \/]# \n\n# \u901a\u8fc7attach\u547d\u4ee4\u8fdb\u5165\u5bb9\u5668\u7684\u63a7\u5236\u53f0\n$ docker attach 582eb515c4ee\n[root@582eb515c4ee \/]# \n<\/code><\/pre>\n<\/li>\n<\/ul>\n<ol start=\"9\">\n<li>\u9000\u51fa\u5bb9\u5668: <code>Ctrl + P + Q<\/code>  <strong>\u6ce8\u610f\u987a\u5e8f\u4e0d\u80fd\u4e71<\/strong><\/p>\n<\/li>\n<li>\n<p>\u505c\u6b62\u5bb9\u5668<\/p>\n<pre><code class=\"language-shell line-numbers\"># \u901a\u8fc7id\u6216\u540d\u79f0\u6765\u64cd\u4f5c\n$ docker stop sleepy_babbage \nsleepy_babbage\n<\/code><\/pre>\n<\/li>\n<li>\u5220\u9664\u5bb9\u5668\n<pre><code class=\"language-shell line-numbers\"> # \u5220\u9664\u5bb9\u5668\u901a\u8fc7id\u6216\u540d\u79f0\u6765\u5220\u9664\n $ docker rm 0d320f497f02\n 0d320f497f02\n<\/code><\/pre>\n<\/li>\n<li>\u7aef\u53e3\u6620\u5c04\n<pre><code class=\"language-shell line-numbers\"> # \u5bbf\u4e3b\u4e3b\u673a\u76841080\u7aef\u53e3\u6620\u5c04\u5230\u5bb9\u5668\u4e2d\u4e3b\u673a\u768480\u7aef\u53e3\n $ docker run -d -p 1080:80 nginx\n eace3d16b4f19e5d555bddc90c57a5b261196c62f1482513cfabc5b6ec7d4cce\n\n # \u67e5\u770b\u521b\u5efa\u597d\u7684\u5bb9\u5668\n $ docker ps\n CONTAINER ID   IMAGE       COMMAND                  CREATED          STATUS          PORTS                  NAMES\n eace3d16b4f1   nginx       \"\/docker-entrypoint.\u2026\"   3 seconds ago    Up 1 second     0.0.0.0:1080-&gt;80\/tcp   gallant_maxwell\n<\/code><\/pre>\n<\/li>\n<li>\u5377\u5b97\u6620\u5c04\n<pre><code class=\"language-shell line-numbers\"># \u5c06\u5bbf\u4e3b\u673a\u4e2d\/root\/data \u76ee\u5f55\u6302\u8f7d\u5230 \u5bb9\u5668\u4e2d\/data\u76ee\u5f55\n$ docker create -it -v \/root\/docker:\/data centos bash\na0c4b4f3bcc256193c49e86b88a1eb239051c955a5e6af031e821d7d3644d755\n\n#\u67e5\u770b\u6302\u8f7d\u8be6\u60c5\n$ docker inspect a0c4b4f3bcc2\n\"Mounts\": [\n    {\n        \"Type\": \"bind\",\n        \"Source\": \"\/root\/docker\",\n        \"Destination\": \"\/data\",\n        \"Mode\": \"\",\n        \"RW\": true,\n        \"Propagation\": \"rprivate\"\n    }\n],\n<\/code><\/pre>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u641c\u7d22\u955c\u50cf $ docker search centos NAME DESCRIPTION STARS OFFICIAL AUTOMATED centos The official build of CentOS. 6385 [OK] ansible\/centos7-ansible Ansible on Centos7 132 [OK] consol\/centos-xfce-vnc Centos container with &#8220;headless&#8221; VNC session\u2026 125 [OK] jdeathe\/centos-ssh OpenSSH \/ Supervisor \/ EPEL\/IUS\/SCL Repos &#8211; \u2026 117 [OK] centos\/systemd systemd enabled base container. 93 [OK] centos\/mysql-57-centos7 MySQL 5.7 SQL [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[345],"tags":[346],"class_list":["post-1964","post","type-post","status-publish","format-standard","hentry","category-devops","tag-docker"],"_links":{"self":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/1964","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/comments?post=1964"}],"version-history":[{"count":0,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/1964\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/media?parent=1964"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/categories?post=1964"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/tags?post=1964"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}