\r\n[root@Docker ~]# docker images\r\nREPOSITORY TAG IMAGE ID CREATED SIZE\r\ncentos latest 470671670cac 4 months ago 237MB\r\n<\/pre>\n\u6839\u636e\u5bb9\u5668\u5f53\u524d\u72b6\u6001\u505a\u4e00\u4e2a image \u955c\u50cf\uff1a\u521b\u5efa\u4e00\u4e2a\u5b89\u88c5\u4e86 apache \u5de5\u5177\u7684 centos \u955c\u50cf<\/p>\n
\u8bed\u6cd5\uff1a docker commit \"container \u7684 ID\" \u6216 \"image_name\"<\/p>\n
\u67e5\u770b\u5bb9\u5668 ID<\/p>\n
\r\n[root@Docker ~]# docker ps -a\r\nCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES\r\n1b96e68a3cce centos:latest \"\/bin\/bash\" 3 minutes ago Exited (0) 2 minutes ago awesome_hypatia\r\n607752360adf centos:latest \"\/bin\/bash -c 'while\u2026\" 18 minutes ago Exited (137) 12 minutes ago brave_fermi\r\n0a297ff99af8 centos:latest \"\/bin\/bash\" 22 minutes ago Exited (1) 20 minutes ago ecstatic_yonath\r\nefb4af688330 centos:latest \"\/bin\/bash\" 24 minutes ago Exited (0) 23 minutes ago epic_mcclintock\r\n[root@Docker ~]# docker commit 1b96e68a3cce centos:apache\r\nsha256:b8822ec8a7bbb325793e7908e355180be82a49481cff197661fb5d0da5872e88\r\n[root@Docker ~]# docker images\r\nREPOSITORY TAG IMAGE ID CREATED SIZE\r\ncentos apache b8822ec8a7bb 9 seconds ago 280MB\r\ncentos latest 470671670cac 4 months ago 237MB\r\n<\/pre>\n\u4f7f\u7528\u65b0\u521b\u5efa\u7684 centos:apache \u955c\u50cf\uff0c\u751f\u6210\u4e00\u4e2a\u5bb9\u5668\u5b9e\u4f8b<\/p>\n
\r\n[root@Docker ~]# docker run -it centos:apache \/bin\/bash\r\n[root@e4c295d27581 \/]# rpm -qa httpd \r\nhttpd-2.4.37-16.module_el8.1.0+256+ae790463.x86_64\r\n<\/pre>\n\u770b\u5230httpd\u8f6f\u4ef6\u540d\u79f0\u8bf4\u660e\u57fa\u4e8e apache \u955c\u50cf\u7684\u5bb9\u5668\u521b\u5efa\u6210\u529f<\/p>\n
\u65b9\u6cd5\u4e8c\uff1a\u901a\u8fc7\uff1adocker build \u521b\u5efa\u4e00\u4e2a\u57fa\u4e8e centos \u7684 httpd web \u670d\u52a1\u5668\u955c\u50cf<\/strong><\/div>\n\u4f7f\u7528 docker build \u521b\u5efa\u955c\u50cf\u65f6\uff0c\u9700\u8981\u4f7f\u7528 Dockerfile \u6587\u4ef6\u81ea\u52a8\u5316\u5236\u4f5c image \u955c\u50cf
\nDockerfile \u6709\u70b9\u50cf\u6e90\u7801\u7f16\u8bd1\u65f6.\/configure \u540e\u4ea7\u751f\u7684 Makefile<\/p>\n
1\u3001\u521b\u5efa\u5de5\u4f5c\u76ee\u5f55<\/strong><\/span><\/div>\n\r\n[root@Docker ~]# mkdir \/docker-build\r\n[root@Docker ~]# cd \/docker-build\r\n[root@Docker docker-build]# touch Dockerfile\r\n[root@Docker docker-build]# ls\r\nDockerfile\r\n\u6ce8\uff1a make \u81ea\u52a8\u5316\u7f16\u8bd1\u65f6\u9700\u8981 Makefile \u6587\u4ef6\uff0c\u81ea\u52a8\u5316\u521b\u5efa docker \u955c\u50cf\u65f6\uff0c\u9700\u8981 Dockerfile\r\n<\/pre>\n2\u3001\u7f16\u8f91 Dockerfile<\/strong><\/span><\/div>\n\r\nDockerfile \u7528\u6765\u521b\u5efa\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684 image,\u5305\u542b\u4e86\u7528\u6237\u6303\u5b9a\u7684\u8f6f\u4ef6\u4f9d\u8d56\u7b49\u3002\r\n[root@Docker docker-build ]# vim Dockerfile\r\nFROM centos:latest\r\nMAINTAINER \r\nRUN yum -y install httpd\r\nADD start.sh \/usr\/local\/bin\/start.sh\r\nADD index.html \/var\/www\/html\/index.html\r\nCMD echo hello world\r\n<\/pre>\n\u6ce8\u91ca<\/p>\n
\r\nFROM centos:latest # FROM \u57fa\u4e8e\u54ea\u4e2a\u955c\u50cf\r\nMAINTAINER # MAINTAINER \u955c\u50cf\u521b\u5efa\u8005\r\nRUN yum -y install httpd #RUN \u5b89\u88c5\u8f6f\u4ef6\u7528\r\nADD start.sh \/usr\/local\/bin\/start.sh\r\nADD index.html \/var\/www\/html\/index.html\r\n# ADD \u5c06\u6587\u4ef6\u62f7\u8d1d\u5230\u65b0\u4ea7\u751f\u7684\u955c\u50cf\u7684\u6587\u4ef6\u7cfb\u7edf\u5bf9\u5e94\u7684\u8def\u5f84\u3002\u6240\u6709\u62f7\u8d1d\u5230\u65b0\u955c\u50cf\u4e2d\u7684\r\n\u6587\u4ef6\u548c\u6587\u4ef6\u5939\u6743\u9650\u4e3a 0755,uid \u548c gid \u4e3a 0\r\nCMD echo hello world #container \u542f\u52a8\u65f6\u6267\u884c\u7684\u547d\u4ee4\u6216\u542f\u52a8\u670d\u52a1\uff0c\u4f46\u662f\u4e00\u4e2a Dockerfile \u4e2d\u53ea\u80fd\u6709\u4e00\u6761 CMD \u547d\u4ee4\uff0c\u6709\u591a\u6761\u5219\u53e6\u6267\u884c\u6700\u540e\u4e00\u6761 CMD\r\n<\/dest><\/src><\/pre>\n3\u3001\u521b\u5efa start.sh \u811a\u672c\u542f\u52a8 httpd \u670d\u52a1\u548c apache \u9ed8\u8ba4\u9996\u9875 index.html \u6587\u4ef6<\/strong><\/span><\/div>\n\r\n[root@Docker docker-build ]# echo \"#!\/bin\/bash\" >> start.sh\r\n[root@Docker docker-build ]# echo \"\/usr\/sbin\/httpd -DFOREGROUND\" >> start.sh\r\n\u6ce8\uff1a\/usr\/sbin\/httpd -DFOREGROUND \u76f8\u5f53\u4e8e\u6267\u884c\u4e86 systemctl start httpd\r\n\r\n[root@Docker docker-build ]# chmod a+x start.sh\r\n\r\n\u521b\u5efa index.html\r\n[root@Docker docker-build ]# echo \"docker image build test from jaking\" > index.html\r\n<\/pre>\n4\u3001\u4f7f\u7528\u547d\u4ee4 build \u6765\u521b\u5efa\u65b0\u7684 image<\/strong><\/span><\/div>\n\u8bed\u6cd5\uff1adocker build -t \u7236\u955c\u50cf\u540d\uff1a\u955c\u50cf\u7684 tag Dockerfile \u6587\u4ef6\u6240\u5728\u8def\u5f84
\n-t :\u8868\u793a tag\uff0c\u955c\u50cf\u540d<\/p>\n
\u4f8b\uff1a\u4f7f\u7528\u547d\u4ee4 docker build \u6765\u521b\u5efa\u65b0\u7684 image,\u5e76\u547d\u540d\u4e3a centos:httpd<\/p>\n
\r\n[root@Docker docker-build]# ls\r\nDockerfile index.html start.sh\r\n[root@Docker docker-build]# docker build -t centos:httpd .\/\r\n# \u6ce8\uff1a .\/ \u8868\u793a\u5f53\u524d\u76ee\u5f55,\u53e6\u5916\u4f60\u7684\u5f53\u524d\u76ee\u5f55\u4e0b\u8981\u5305\u542b Dockerfile\r\nSending build context to Docker daemon 4.096kB\r\nStep 1\/5 : FROM centos:latest\r\n ---> 470671670cac\r\nStep 2\/5 : MAINTAINER \r\n ---> Running in 0180810d2ab3\r\nRemoving intermediate container 0180810d2ab3\r\n ---> 5b9af0184bcf\r\nStep 3\/5 : RUN yum -y install httpd\r\n ---> Running in 8f5c114649ed\r\nCentOS-8 - AppStream 228 kB\/s | 7.0 MB 00:31 \r\nCentOS-8 - Base 547 kB\/s | 2.2 MB 00:04 \r\nCentOS-8 - Extras 431 B\/s | 5.9 kB 00:14 \r\nDependencies resolved.\r\n================================================================================\r\n Package Arch Version Repo Size\r\n================================================================================\r\nInstalling:\r\n httpd x86_64 2.4.37-16.module_el8.1.0+256+ae790463 AppStream 1.7 M\r\nInstalling dependencies:\r\n apr x86_64 1.6.3-9.el8 AppStream 125 k\r\n apr-util x86_64 1.6.1-6.el8 AppStream 105 k\r\n centos-logos-httpd\r\n noarch 80.5-2.el8 AppStream 24 k\r\n\r\n ...\u7701\u7565\u90e8\u5206\u8f93\u51fa\u4fe1\u606f... \r\n\r\nComplete!\r\nRemoving intermediate container 8f5c114649ed\r\n ---> 040b5f229962\r\nStep 4\/5 : ADD start.sh \/usr\/local\/bin\/start.sh\r\n ---> 11a106005031\r\nStep 5\/5 : ADD index.html \/var\/www\/html\/index.html\r\n ---> 85b4a3657ced\r\nSuccessfully built 85b4a3657ced\r\nSuccessfully tagged centos:httpd\r\n<\/pre>\n\u67e5\u770b images \u5217\u8868<\/p>\n
\r\n[root@Docker docker-build]# docker images\r\nREPOSITORY TAG IMAGE ID CREATED SIZE\r\ncentos httpd 85b4a3657ced 45 seconds ago 280MB\r\ncentos apache b8822ec8a7bb 20 minutes ago 280MB\r\ncentos latest 470671670cac 4 months ago 237MB\r\n# \u6ce8\uff1adocker \u955c\u50cf=\u5e94\u7528\/\u7a0b\u5e8f+\u5e93\r\n<\/pre>\n\u8fd0\u884c\u65b0\u751f\u6210\u7684\u955c\u50cf<\/p>\n
\r\n[root@Docker docker-build]# docker run -it centos:httpd \/bin\/bash \r\n[root@1188a43a4585 \/]# ls\r\nbin etc lib lost+found mnt proc run srv tmp var\r\ndev home lib64 media opt root sbin sys usr\r\n[root@1188a43a4585 \/]# rpm -qa httpd\r\nhttpd-2.4.37-16.module_el8.1.0+256+ae790463.x86_64\r\n[root@1188a43a4585 \/]# exit\r\nexit\r\n[root@Docker docker-build]#\r\n<\/pre>\n\u603b\u7ed3<\/strong><\/div>\n\u4ee5\u4e0a\u5c31\u662f Docker \u955c\u50cf\u5236\u4f5c\u65b9\u6cd5\u7684\u4ecb\u7ecd\uff0c\u5e0c\u671b\u80fd\u7ed9\u5927\u5bb6\u5e26\u6765\u5e2e\u52a9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
\u65b9\u6cd5 1\uff1adocker commit #\u4fdd\u5b58 container \u7684\u5f53\u524d\u72b6\u6001\u5230 image \u540e\uff0c\u7136\u540e\u751f\u6210\u5bf9\u5e94\u7684 […]<\/p>\n","protected":false},"author":63,"featured_media":192368,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-192366","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\/192366","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=192366"}],"version-history":[{"count":8,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/192366\/revisions"}],"predecessor-version":[{"id":192470,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/192366\/revisions\/192470"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/192368"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=192366"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=192366"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=192366"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}