{"id":110908,"date":"2024-11-30T02:35:10","date_gmt":"2024-11-29T18:35:10","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=110908"},"modified":"2024-11-30T02:35:11","modified_gmt":"2024-11-29T18:35:11","slug":"dockerfile-create-mirror","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/dockerfile-create-mirror.html","title":{"rendered":"\u4e00\u8d77\u8ddf\u6211\u6765\u5b66dockerfile\u521b\u5efa\u955c\u50cf"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nDocker \u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u5e94\u7528\u5bb9\u5668\u5f15\u64ce\uff0c\u8ba9\u5f00\u53d1\u8005\u53ef\u4ee5\u6253\u5305\u4ed6\u4eec\u7684\u5e94\u7528\u4ee5\u53ca\u4f9d\u8d56\u5305\u5230\u4e00\u4e2a\u53ef\u79fb\u690d\u7684\u5bb9\u5668\u4e2d\uff0c\u7136\u540e\u53d1\u5e03\u5230\u4efb\u4f55\u6d41\u884c\u7684 Linux \u673a\u5668\u4e0a\uff0c\u4e5f\u53ef\u4ee5\u5b9e\u73b0\u865a\u62df\u5316\u3002\u5bb9\u5668\u662f\u5b8c\u5168\u4f7f\u7528\u6c99\u7bb1\u673a\u5236\uff0c\u76f8\u4e92\u4e4b\u95f4\u4e0d\u4f1a\u6709\u4efb\u4f55\u63a5\u53e3\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

docker\u547d\u4ee4\u8bed\u6cd5<\/strong><\/div>\n
1.ADD\r\nADD\u547d\u4ee4\u6709\u4e24\u4e2a\u53c2\u6570\uff0c\u6e90\u548c\u76ee\u6807\u3002\u5b83\u7684\u57fa\u672c\u4f5c\u7528\u662f\u4ece\u6e90\u7cfb\u7edf\u7684\u6587\u4ef6\u7cfb\u7edf\u4e0a\u590d\u5236\u6587\u4ef6\u5230\u76ee\u6807\u5bb9\u5668\u7684\u6587\u4ef6\u7cfb\u7edf\u3002\u5982\u679c\u6e90\u662f\u4e00\u4e2aURL\uff0c\u90a3\u8be5URL\u7684\u5185\u5bb9\u5c06\u88ab\u4e0b\u8f7d\u5e76\u590d\u5236\u5230\u5bb9\u5668\u4e2d\r\nADD \/my_app_folder \/my_app_folder\r\n\r\n2.ENTRYPOINT\r\n\u914d\u7f6e\u5bb9\u5668\u542f\u52a8\u540e\u6267\u884c\u7684\u547d\u4ee4\uff0c\u5e76\u4e14\u4e0d\u53ef\u88ab docker run \u63d0\u4f9b\u7684\u53c2\u6570\u8986\u76d6\uff0c\u6bcf\u4e2a Dockerfile \u4e2d\u53ea\u80fd\u6709\u4e00\u4e2a ENTRYPOINT\uff0c\u5f53\u6307\u5b9a\u591a\u4e2a\u65f6\uff0c\u53ea\u6709\u6700\u540e\u4e00\u4e2a\u8d77\u6548\u3002\r\n\r\n3.ENV \r\nENV\u547d\u4ee4\u7528\u4e8e\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u3002\u8fd9\u4e9b\u53d8\u91cf\u4ee5\u201dkey=value\u201d\u7684\u5f62\u5f0f\u5b58\u5728\uff0c\u5e76\u53ef\u4ee5\u5728\u5bb9\u5668\u5185\u88ab\u811a\u672c\u6216\u8005\u7a0b\u5e8f\u8c03\u7528\u3002\u8fd9\u4e2a\u673a\u5236\u7ed9\u5728\u5bb9\u5668\u4e2d\u8fd0\u884c\u5e94\u7528\u5e26\u6765\u4e86\u6781\u5927\u7684\u4fbf\u5229\u3002  \r\nENV PATH \/usr\/local\/nginx\/sbin:$PATH\r\n\r\n4.EXPOSE \r\nEXPOSE\u7528\u6765\u6307\u5b9a\u7aef\u53e3\uff0c\u4f7f\u5bb9\u5668\u5185\u7684\u5e94\u7528\u53ef\u4ee5\u901a\u8fc7\u7aef\u53e3\u548c\u5916\u754c\u4ea4\u4e92\u3002 \r\nEXPOSE 80\r\n\r\n5.FROM \r\n\u8fd9\u4e2a\u547d\u4ee4\u7528\u4e8e\u58f0\u660e\u4f5c\u8005\uff0c\u5e76\u5e94\u8be5\u653e\u5728FROM\u7684\u540e\u9762\u3002   \r\nMAINTAINER authors_name \r\n\r\n6.RUN\r\n\r\n7.USER\r\nUSER\u547d\u4ee4\u7528\u4e8e\u8bbe\u7f6e\u8fd0\u884c\u5bb9\u5668\u7684UID\u3002\r\n\r\n8.WORKDIR\r\nWORKDIR\u547d\u4ee4\u7528\u4e8e\u8bbe\u7f6eCMD\u6307\u660e\u7684\u547d\u4ee4\u7684\u8fd0\u884c\u76ee\u5f55\u3002\r\n<\/pre>\n
dockerfile\u521b\u5efa\u955c\u50cf<\/strong><\/div>\n

\u4e0b\u9762\u5c31\u6784\u5efa\u4e00\u4e2a\u7b80\u5355\u7684dockerfile<\/p>\n

1.\u9700\u8981\u4e00\u4e2a\u57fa\u7840\u955c\u50cf<\/p>\n

docker pull centos<\/pre>\n

2.\u5728\u67d0\u4e00\u4e2a\u76ee\u5f55\u4e0b\u9762\u521b\u5efa\u4e00\u4e2a\u4e13\u95e8\u5b58\u653e\u6b64demo\u7684\u76ee\u5f55\uff0c\u4e5f\u5c31\u662fDockerfile\u6240\u5728\u7684context\uff1a<\/p>\n

[root@docker ~]# mkdir docker_demo\r\n[root@docker ~]# cd docker_demo\/\r\n[root@docker docker_demo]# touch Dockerfile\r\n[root@docker docker_demo]# pwd\r\n\/root\/docker_demo\r\n[root@docker docker_demo]# ll\r\ntotal 0\r\n-rw-r--r--. 1 root root 0 Nov 1 04:34 Dockerfile\r\n\r\n \r\n\r\n\u4e0b\u8f7dnginx\u6e90\u7801\u5305\u5230docker_demo\u8fd9\u4e2a\u76ee\u5f55\u4e0b\uff1a\r\n\r\n[root@docker docker_demo]# ll\r\ntotal 960\r\n-rw-r--r--. 1 root root      0 Nov  1 04:34 Dockerfile\r\n-rw-r--r--. 1 root root 981687 Oct 17 09:20 nginx-1.12.2.tar.gz\r\n\r\n\u4ee5\u4e0b\u662f\u7f16\u5199\u597d\u7684Dockerfile v1\u7248\uff1a\r\n\r\n[root@docker docker_demo]# cat Dockerfile \r\n# base image\r\nFROM centos\r\n# MAINTAINER\r\nMAINTAINER json_hc@163.com\r\n# put nginx-1.12.2.tar.gz into \/usr\/local\/src and unpack nginx\r\nADD nginx-1.12.2.tar.gz \/usr\/local\/src\r\n# running required command\r\nRUN yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel \r\nRUN yum install -y libxslt-devel -y gd gd-devel GeoIP GeoIP-devel pcre pcre-devel\r\nRUN useradd -M -s \/sbin\/nologin nginx\r\n# change dir to \/usr\/local\/src\/nginx-1.12.2\r\nWORKDIR \/usr\/local\/src\/nginx-1.12.2\r\n# execute command to compile nginx\r\nRUN .\/configure --user=nginx --group=nginx --prefix=\/usr\/local\/nginx --with-file-aio --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module && make && make install\r\n\r\nENV PATH \/usr\/local\/nginx\/sbin:$PATH\r\n\r\n\r\nEXPOSE 80\r\n\r\n\r\n\r\n[root@docker docker_demo]# docker build -t centos_nginx:v2 .\r\nSending build context to Docker daemon 985.6kB\r\nStep 1\/10 : FROM centos\r\n---> 196e0ce0c9fb\r\nStep 2\/10 : MAINTAINER json_hc@163.com\r\n---> Using cache\r\n---> cde1d7830106\r\nStep 3\/10 : ADD nginx-1.12.2.tar.gz \/usr\/local\/src\r\n---> Using cache\r\n---> 1e4d16340af0\r\nStep 4\/10 : RUN yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel\r\n---> Using cache\r\n---> 405835ad9b0b\r\nStep 5\/10 : RUN yum install -y libxslt-devel -y gd gd-devel GeoIP GeoIP-devel pcre pcre-devel\r\n---> Using cache\r\n---> 4002738cf7a6\r\nStep 6\/10 : RUN useradd -M -s \/sbin\/nologin nginx\r\n---> Using cache\r\n---> 02961c5c564d\r\nStep 7\/10 : WORKDIR \/usr\/local\/src\/nginx-1.12.2\r\n---> Using cache\r\n---> f1da71a93c5e\r\nStep 8\/10 : RUN .\/configure --user=nginx --group=nginx --prefix=\/usr\/local\/nginx --with-file-aio --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module && make && make install\r\n---> Using cache\r\n---> cd2ad4c45004\r\nStep 9\/10 : ENV PATH \/usr\/local\/nginx\/sbin:$PATH\r\n---> Running in 07ba2f7129bc\r\n---> 9588fa1058aa\r\nRemoving intermediate container 07ba2f7129bc\r\nStep 10\/10 : EXPOSE 80\r\n---> Running in 473cd847154a\r\n---> 2031faf8894a\r\nRemoving intermediate container 473cd847154a\r\nSuccessfully built 2031faf8894a\r\nSuccessfully tagged centos_nginx:v2\r\n\r\n \r\n\r\n$ docker images\r\n\r\n$ docker run -d -p81:80 centos_nginx nginx -g \"daemon off;\"\r\n\r\n$ docker ps -l\r\n<\/pre>\n

\u6700\u540e\u901a\u8fc7\u6d4f\u89c8\u5668\u8bbf\u95ee\u5c31\u53ef\u4ee5\u4e86<\/p>\n

\n

\u539f\u6587\u6765\u81ea\uff1ahttps:\/\/www.cnblogs.com\/394510636-ff\/p\/9276934.html<\/a><\/p>\n

\u672c\u6587\u5730\u5740\uff1ahttps:\/\/lrxjmw.cn\/dockerfile-create-mirror.html<\/a>\u7f16\u8f91\uff1a\u51af\u745e\u6d9b\uff0c\u5ba1\u6838\u5458\uff1a\u9004\u589e\u5b9d<\/span><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"

\u5bfc\u8bfb Docker \u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u5e94\u7528\u5bb9\u5668\u5f15\u64ce\uff0c\u8ba9\u5f00\u53d1\u8005\u53ef\u4ee5\u6253\u5305\u4ed6\u4eec\u7684\u5e94\u7528\u4ee5\u53ca\u4f9d\u8d56\u5305\u5230\u4e00\u4e2a\u53ef\u79fb\u690d\u7684\u5bb9\u5668\u4e2d\uff0c\u7136\u540e\u53d1 […]<\/p>\n","protected":false},"author":1329,"featured_media":110911,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-110908","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\/110908","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\/1329"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=110908"}],"version-history":[{"count":4,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/110908\/revisions"}],"predecessor-version":[{"id":111106,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/110908\/revisions\/111106"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/110911"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=110908"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=110908"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=110908"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}