{"id":192374,"date":"2020-05-27T08:22:52","date_gmt":"2020-05-27T00:22:52","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=192374"},"modified":"2020-05-25T09:21:22","modified_gmt":"2020-05-25T01:21:22","slug":"docker-image-container","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/docker-image-container.html","title":{"rendered":"Docker Image \u7684\u53d1\u5e03\u548c Container \u7aef\u53e3\u6620\u5c04"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5728\u6309\u7167\u672c\u6587\u6863\u7684\u6b65\u9aa4\u64cd\u4f5c\u524d\uff0c\u9700\u8981\u5b89\u88c5\u597d Docker<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
Docker Image \u7684\u53d1\u5e03<\/strong><\/div>\n
\u65b9\u6cd51\uff1a\u4fdd\u5b58 Image \u5230 tar \u5305<\/strong><\/span><\/div>\n

\u8bed\u6cd5\uff1adocker save -o \u5bfc\u51fa\u7684\u955c\u50cf\u540d.tar \u672c\u5730\u955c\u50cf\u540d\uff1a\u955c\u50cf\u6807\u7b7e<\/p>\n

\r\n[root@Docker docker-build]# docker save -o centos-httpd-docker-image.tar centos:httpd\r\n[root@Docker docker-build]# ll -h\r\ntotal 275M\r\n-rw-r--r--. 1 root root  154 May 17 23:19 Dockerfile\r\n-rw-------. 1 root root 275M May 17 23:37 centos-httpd-docker-image.tar\r\n-rw-r--r--. 1 root root   37 May 17 23:27 index.html\r\n-rwxr-xr-x. 1 root root   29 May 17 23:25 start.sh\r\n<\/pre>\n

\u4f7f\u7528\u5bfc\u5165\u672c\u5730\u955c\u50cf<\/p>\n

[root@Docker docker-build]# docker rmi -f centos:httpd #\u5220\u9664\u955c\u50cf\uff0c\u8fd9\u91cc\u5199\u81ea\u5df1\u955c\u50cf\u7684 ID \u6216\u540d\u79f0<\/pre>\n
\r\n[root@Docker docker-build]# docker images\r\nREPOSITORY          TAG                 IMAGE ID            CREATED             SIZE\r\ncentos              apache              b8822ec8a7bb        27 minutes ago      280MB\r\ncentos              latest              470671670cac        4 months ago        237MB\r\n[root@Docker docker-build]# docker load -i centos-httpd-docker-image.tar\r\nLoaded image: centos:httpd\r\n[root@Docker docker-build]# docker images\r\nREPOSITORY          TAG                 IMAGE ID            CREATED             SIZE\r\ncentos              httpd               85b4a3657ced        8 minutes ago       280MB\r\ncentos              apache              b8822ec8a7bb        29 minutes ago      280MB\r\ncentos              latest              470671670cac        4 months ago        237MB\r\n<\/pre>\n
\u65b9\u6cd5 2\uff1aPush Image To Docker Hub \u53d1\u5e03\u5230\u5916\u7f51<\/strong><\/span><\/div>\n
\r\n1\u3001Signup on docker hub & create repo \u6ce8\u518c\u4e00\u4e2a\u5e10\u53f7\r\nhttps:\/\/hub.docker.com\/\r\n2\u3001Login to docker hub\r\n# docker login -u userabc -p abc123 -e jaking@gmail.com\r\n3\u3001Push image to docker hub #\u4e0a\u4f20\u955c\u50cf\r\n# docker push centos:httpd\r\n4\u3001Pull image from docker hub #\u4e0b\u8f7d\u955c\u50cf\r\n# docker pull userabc\/centos:httpd # \u7528\u6237\u540d\/\u955c\u50cf\u540d\r\n<\/pre>\n
Container \u5bb9\u5668\u7aef\u53e3\u6620\u5c04<\/strong><\/div>\n
\u5b9e\u6218\uff1aContainer \u7aef\u53e3\u6620\u5c04<\/strong><\/span><\/div>\n

\u542f\u52a8 container<\/strong><\/p>\n

\r\n[root@Docker ~]# docker run -d -p 80:80 centos:httpd \/bin\/bash -c \/usr\/local\/bin\/start.sh\r\ncf183879c15bd06523ecb6b5e19aec561d679fa5f3bd1842cb2d2994f0d79b04\r\n<\/pre>\n

\u6ce8\uff1a -p \u7269\u7406\u673a\u7684 80 \u7aef\u53e3:\u5bb9\u5668\u5b9e\u4f8b\u7684 80 \u7aef\u53e3 \uff0c\u628a\u5bb9\u5668\u4e2d\u7684 80 \u7aef\u53e3\u6620\u5c04\u5230\u7269\u7406\u673a\u4e0a\u7684 80 \u7aef\u53e3<\/p>\n

\u53e6\u4e00\u79cd\u542f\u52a8\u65b9\u5f0f<\/strong><\/p>\n

\r\n[root@Docker ~]# cd \/docker-build\r\n[root@Docker docker-build]# docker run -d -p 80:80 centos:httpd \/bin\/bash -c start.sh\r\n<\/pre>\n

\u5728\u7269\u7406\u673a\u4e0a\u67e5\u770b\u5bb9\u6613\u72b6\u6001<\/p>\n

\r\n[root@Docker ~]# docker ps\r\nCONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES\r\ncf183879c15b        centos:httpd        \"\/bin\/bash -c \/usr\/l\u2026\"   24 seconds ago      Up 23 seconds       0.0.0.0:80->80\/tcp   happy_mahavira\r\n<\/pre>\n

\u67e5\u770b\u7269\u7406\u673a\u4e0a\u5f00\u542f\u7684 80 \u4ee3\u7406\u7aef\u53e3<\/p>\n

\r\n[root@Docker ~]# netstat -pantu | grep 80\r\ntcp6       0      0 :::80                   :::*                    LISTEN      10870\/docker-proxy  \r\nudp6       0      0 fe80::c43:91ff:fe1a:123 :::*                                7829\/ntpd           \r\nudp6       0      0 fe80::42:deff:fe9c::123 :::*                                7829\/ntpd           \r\nudp6       0      0 fe80::250:56ff:fe35:123 :::*                                7829\/ntpd      \r\n<\/pre>\n
\u6d4b\u8bd5<\/strong><\/div>\n

\u5728\u6d4f\u89c8\u5668\u8f93\u5165 http:\/\/192.168.10.7
\n\"\"<\/p>\n

\u603b\u7ed3<\/strong><\/div>\n

\u4ee5\u4e0a\u5c31\u662f Docker Image \u7684\u53d1\u5e03\u548c Container \u7aef\u53e3\u6620\u5c04\u7684\u64cd\u4f5c\u8fc7\u7a0b\uff0c\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u8bed\u6cd5\uff1adocker save -o \u5bfc\u51fa\u7684\u955c\u50cf\u540d.tar \u672c\u5730\u955c\u50cf\u540d\uff1a\u955c\u50cf\u6807\u7b7e [root@Docker do […]<\/p>\n","protected":false},"author":63,"featured_media":192376,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-192374","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\/192374","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=192374"}],"version-history":[{"count":5,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/192374\/revisions"}],"predecessor-version":[{"id":192467,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/192374\/revisions\/192467"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/192376"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=192374"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=192374"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=192374"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}