{"id":178015,"date":"2020-05-07T09:27:20","date_gmt":"2020-05-07T01:27:20","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=178015"},"modified":"2020-04-24T10:30:15","modified_gmt":"2020-04-24T02:30:15","slug":"linux-docker-create","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-docker-create.html","title":{"rendered":"Linux Docker\u79c1\u6709\u4ed3\u5e93\u642d\u5efa\u6559\u7a0b"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u521b\u5efadocker\u79c1\u6709\u4ed3\u5e93\u7684\u76ee\u7684\u5728\u4e8e\u79c1\u5bc6\u6027\uff0c\u9002\u7528\u4e8e\u56e2\u4f53\u5185\u90e8\uff0c\u5982\u516c\u53f8\u90e8\u95e8\uff0c\u4f01\u4e1a\u5185\u90e8\u7b49\u9700\u8981\u5728\u56e2\u4f53\u6210\u5458\u4e2d\u5171\u4eabdocker\u76f8\u5173\u8d44\u6e90\u7684\u573a\u666f\u3002
\n\u200b\u90a3\u4e48\u5982\u4f55\u642d\u5efa\u5c5e\u4e8e\u81ea\u5df1\u4f01\u4e1a\u6216\u56e2\u4f53\u6210\u5458\u53ef\u4ee5\u4f7f\u7528\u7684docker\u79c1\u6709\u4ed3\u5e93\u5462\uff1f\u7b14\u8005\u5c06\u901a\u8fc7\u4e0b\u9762\u7684\u5b9e\u9645\u642d\u5efa\u6d41\u7a0b\u7ed3\u5408\u6b65\u9aa4\u63cf\u8ff0\u6765\u4ecb\u7ecddocker\u79c1\u6709\u4ed3\u5e93\u642d\u5efa\u7684\u5177\u4f53\u8fc7\u7a0b\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
1\u3001\u4e0b\u8f7dregistry\u955c\u50cf<\/strong><\/div>\n
[root@localhost ~]# docker pull registry\r\nUsing default tag: latest\r\nlatest: Pulling from library\/registry\r\n486039affc0a: Pull complete\r\nba51a3b098e6: Pull complete\r\n8bb4c43d6c8e: Pull complete\r\n6f5f453e5f2d: Pull complete\r\n42bc10b72f42: Pull complete\r\nDigest: sha256:7d081088e4bfd632a88e3f3bcd9e007ef44a796fddfe3261407a3f9f04abe1e7\r\nStatus: Downloaded newer image for registry:latest\r\ndocker.io\/library\/registry:latest<\/pre>\n
2\u3001\u751f\u6210registry\u5bb9\u5668\uff0c\u5f00\u653e5000\u7aef\u53e3<\/strong><\/div>\n
[root@localhost ~]# docker create -it registry \/bin\/bash\r\nfd51aa59dc5cea7b589d0403e562cb8f0098c3a8a7da239572dd5bfd9423ec96\r\n[root@localhost ~]# docker ps -a\r\nCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES\r\nfd51aa59dc5c registry \"\/entrypoint.sh \/bin\u2026\" 10 seconds ago Created optimistic_saha\r\n#\u5efa\u8bae\u76f4\u63a5\u6267\u884c\u4e0b\u9762\u7684\u8fd9\u4e2a\u547d\u4ee4\uff0c\u56e0\u4e3a\u7b14\u8005\u9047\u5230start\u8fd9\u4e2a\u5bb9\u5668\u53d1\u73b0\u9000\u51fa\u7684\u72b6\u6001\u7801\u975e0\uff08\u540e\u9762\u89e3\u51b3\u4e86\uff0c\u4f7f\u7528\/bin\/sh\u73af\u5883\u5373\u53ef\uff09\r\n[root@localhost ~]# docker run -d -p 5000:5000 -v \/data\/registry:\/tmp\/registry registry\r\nceb498d622ab743fc858a993e3870f9831e20436cb71f7225215f1f0899571f1\r\n[root@localhost ~]# docker ps -a\r\nCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES\r\nceb498d622ab registry \"\/entrypoint.sh \/etc\u2026\" 2 seconds ago Up 2 seconds 0.0.0.0:5000->5000\/tcp strange_swanson\r\n\r\ndocker run -d -p 5000:5000 -v \/data\/registry:\/tmp\/registry registry\u547d\u4ee4\u7684\u89e3\u91ca\uff1a\r\n\r\n-d \u2014\u2014\u5b88\u62a4\u8fdb\u7a0b\r\n\r\n-v \u2014\u2014\u6570\u636e\u5377\u8bbe\u7f6e{\/data\/registry\u8868\u793a\u7684\u5bbf\u4e3b\u673a\u7cfb\u7edf\u4e2d\u7684\u4e00\u4e2a\u7edd\u5bf9\u8def\u5f84\uff0c\u6ca1\u6709\u7684\u65f6\u5019\u4f1a\u81ea\u52a8\u521b\u5efa\uff0c\/tmp\/registry\u8868\u793a\u5bb9\u5668\u5185\u90e8\u7684\u76ee\u5f55}\r\n\r\n#\u5bbf\u4e3b\u673a\u76ee\u5f55\r\n\r\n[root@localhost ~]# ls \/\r\nbin boot data dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var\r\n[root@localhost ~]# ls \/data\/\r\nregistry\r\n\r\n#\u5bb9\u5668\u5185\u90e8\u76ee\u5f55\r\n\r\n[root@localhost ~]# docker exec -it ceb498d622ab \/bin\/sh\r\n\/ # ls \/\r\nbin etc media root srv usr\r\ndev home mnt run sys var\r\nentrypoint.sh lib proc sbin tmp\r\n\/ # ls tmp\/\r\nregistry<\/pre>\n
3\u3001\u5ba2\u6237\u7aef\u8bbe\u7f6edaemon.json\u6587\u4ef6 \uff08\u6307\u5b9a\u79c1\u6709\u4ed3\u5e93\u4f4d\u7f6e\uff09<\/strong><\/div>\n
[root@localhost ~]# vim \/etc\/docker\/daemon.json\r\n\r\n{\r\n\"insecure-registries\": [\"20.0.0.149:5000\"], #\u5c06\u672c\u5730\u670d\u52a1\u5668\u4f5c\u4e3a\u79c1\u6709\u4ed3\u5e93\u4f4d\u7f6e\r\n\"registry-mirrors\": [\"https:\/\/5m9y9qbl.mirror.aliyuncs.com\"]\r\n}\r\n[root@localhost ~]# systemctl restart docker<\/pre>\n
4\u3001\u521b\u5efa\u672c\u5730\u7684\u955c\u50cf\u6807\u7b7e<\/strong><\/div>\n
[root@localhost ~]# docker pull httpd\r\nUsing default tag: latest\r\nlatest: Pulling from library\/httpd\r\n123275d6e508: Pull complete\r\ne984dd982a6e: Pull complete\r\n963280e5cf81: Pull complete\r\n6faf90d050b2: Pull complete\r\n962b56984bb0: Pull complete\r\nDigest: sha256:d5dc0d279039da76a8b490d89a5c96da83a33842493d4336b42ccdfbd36d7409\r\nStatus: Downloaded newer image for httpd:latest\r\ndocker.io\/library\/httpd:latest\r\n\r\n[root@localhost ~]# docker tag httpd:latest 20.0.0.149:5000\/httpd<\/pre>\n
5\u3001\u4e0a\u4f20\u955c\u50cf<\/strong><\/div>\n
[root@localhost ~]# docker push 149:5000\/httpd\r\nThe push refers to repository [149:5000\/httpd]\r\nAn image does not exist locally with the tag: 149:5000\/httpd\r\n[root@localhost ~]# docker push 20.0.0.149:5000\/httpd\r\nThe push refers to repository [20.0.0.149:5000\/httpd]\r\n9dabb51b1ca2: Pushed\r\n4621e8a6d1da: Pushed\r\ne728c649bc91: Pushed\r\n1a935e59aa8a: Pushed\r\nb60e5c3bcef2: Pushed\r\nlatest: digest: sha256:8f10edef61246c6c142a87304d4ffa68298662ecb619776e4e9817d06ec5f567 size: 1367\r\n[root@localhost ~]# curl -XGET http:\/\/20.0.0.149:5000\/v2\/_catalog\r\n{\"repositories\":[\"httpd\"]}\r\n#\u6709\u4e0a\u9762\u7684\u7ed3\u679c\u8868\u793a\u4e0a\u4f20\u6210\u529f<\/pre>\n
6\u3001\u4e0b\u8f7d\u955c\u50cf\u6d4b\u8bd5<\/strong><\/div>\n
[root@localhost ~]# docker images\r\nREPOSITORY TAG IMAGE ID CREATED SIZE\r\nhttpd latest bdc169d27d36 Less than a second ago 166MB\r\n20.0.0.149:5000\/httpd latest bdc169d27d36 Less than a second ago 166MB\r\nregistry latest 708bc6af7e5e 2 months ago 25.8MB\r\n[root@localhost ~]# docker rmi bdc169d27d36\r\nError response from daemon: conflict: unable to delete bdc169d27d36 (must be forced) - image is referenced in multiple repositories\r\n[root@localhost ~]# docker rmi bdc169d27d36 -f\r\nUntagged: 20.0.0.149:5000\/httpd:latest\r\nUntagged: 20.0.0.149:5000\/httpd@sha256:8f10edef61246c6c142a87304d4ffa68298662ecb619776e4e9817d06ec5f567\r\nUntagged: httpd:latest\r\nUntagged: httpd@sha256:d5dc0d279039da76a8b490d89a5c96da83a33842493d4336b42ccdfbd36d7409\r\nDeleted: sha256:bdc169d27d36e2438ec8452c7dd7a52a05561b5de7bef8391849b0513a6f774b\r\nDeleted: sha256:6535aa332fb72ca508f550fef8ffb832d4c6bc72a48720b42659e10d47668181\r\nDeleted: sha256:c7bce1fab718a11501a672c895a729b1fdf8099d00fe152bef8c2534ee455976\r\nDeleted: sha256:75b6b2392924b062257ed97e5c2f3aa9f50a922b94c3f7c342d0aed2370e8bec\r\nDeleted: sha256:267e2020b1bd0b182eb02d1a0f3e2f72efc542890ef6159ed9c3570322608de0\r\nDeleted: sha256:b60e5c3bcef2f42ec42648b3acf7baf6de1fa780ca16d9180f3b4a3f266fe7bc\r\n[root@localhost ~]# docker images\r\nREPOSITORY TAG IMAGE ID CREATED SIZE\r\nregistry latest 708bc6af7e5e 2 months ago 25.8MB\r\n[root@localhost ~]#<\/pre>\n
\u6d4b\u8bd5\uff1a<\/strong><\/span><\/div>\n
[root@localhost ~]# docker pull 20.0.0.149:5000\/httpd\r\nUsing default tag: latest\r\nlatest: Pulling from httpd\r\n123275d6e508: Pull complete\r\ne984dd982a6e: Pull complete\r\n963280e5cf81: Pull complete\r\n6faf90d050b2: Pull complete\r\n962b56984bb0: Pull complete\r\nDigest: sha256:8f10edef61246c6c142a87304d4ffa68298662ecb619776e4e9817d06ec5f567\r\nStatus: Downloaded newer image for 20.0.0.149:5000\/httpd:latest\r\n20.0.0.149:5000\/httpd:latest\r\n[root@localhost ~]#<\/pre>\n

\u62c9\u53d6\u6210\u529f\u5e76\u4e14\u62c9\u53d6\u955c\u50cf\u7684\u901f\u5ea6\u5f88\u5feb\u3002<\/p>\n

\u6700\u540e\u7ed9\u51fa\u4e0a\u9762\u51fa\u73b0\u7684\u72b6\u6001\u7801\u9519\u8bef\u7684\u95ee\u9898\u5177\u4f53\u89e3\u51b3\uff1a<\/p>\n

\"\"<\/p>\n","protected":false},"excerpt":{"rendered":"

[root@localhost ~]# docker pull registry Using default […]<\/p>\n","protected":false},"author":63,"featured_media":178018,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-178015","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/178015","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=178015"}],"version-history":[{"count":2,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/178015\/revisions"}],"predecessor-version":[{"id":178101,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/178015\/revisions\/178101"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/178018"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=178015"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=178015"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=178015"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}