日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

dockerfile中的run_Docker3-Dockerfile创建镜像的方法(推荐docker file这种方法)

發(fā)布時(shí)間:2023/12/19 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 dockerfile中的run_Docker3-Dockerfile创建镜像的方法(推荐docker file这种方法) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

一、鏡像制作的方法

1.本地導(dǎo)入導(dǎo)出鏡像

請(qǐng)參考:Docker 架構(gòu)原理及簡(jiǎn)單使用

導(dǎo)出:docker save nginx >/tmp/nginx.tar.gz導(dǎo)入:docker load

2.docker commit 命令創(chuàng)建鏡像副本

請(qǐng)參考:Docker docker commit方法鏡像制作

3.docker file

前面兩種方法已經(jīng)介紹過(guò)了,這里介紹docker file,生成環(huán)境推薦使用這種方法

二、docker file方法制作鏡像

1.什么是docker file

用來(lái)全自動(dòng)構(gòu)建鏡像文件,命名為Dockerfile

2.Dockerfile 文件編寫指令及語(yǔ)法

1)指令

FROM       MAINTAINER   RUN       CMD      EXPOSEENVADDCOPYENTRYPOINTVOLUMEUSERWORKDIRONBUILD

2)語(yǔ)法

引用了docker中文文檔:http://www.docker.org.cn/dockerppt/114.html

1.FROM   例子:FROM centos  FROM指定構(gòu)建鏡像的基礎(chǔ)源鏡像,如果本地沒(méi)有指定的鏡像,則會(huì)自動(dòng)從Docker的公共庫(kù)pull鏡像下來(lái)。  FROM必須是Dockerfile中非注釋行的第一個(gè)指令,即一個(gè)Dockerfile從FROM語(yǔ)句開(kāi)始  FROM可以在一個(gè)DOCKERfile中出現(xiàn)多次,如果有需求在一個(gè)Dockerfile中創(chuàng)建多個(gè)鏡像2.MAINTAINER   例子:MAINTAINER zxg zhutoyearn@163.com  指定創(chuàng)建鏡像的用戶3.RUN   兩種使用方式:RUNRUN "executable", "param1", "param2"  例子:RUN yum install wget -y   每條RUN指令將在當(dāng)前鏡像基礎(chǔ)上執(zhí)行指定命令,并提交為新的鏡像,后續(xù)的RUN都在之前RUN提交后的鏡像為基礎(chǔ),鏡像是分層的,可以通過(guò)一個(gè)鏡像的任何一個(gè)歷史提交點(diǎn)來(lái)創(chuàng)建,類似源碼的 版本控制 。  exec 方式會(huì)被解析為一個(gè) JSON 數(shù)組,所以必須使用雙引號(hào)而不是單引號(hào)。exec 方式不會(huì)調(diào)用一個(gè)命令 shell,所以也就不會(huì)繼承相應(yīng)的變量,如:  RUN [ "echo", "$HOME" ] #錯(cuò)誤,這個(gè)個(gè)方法不會(huì)輸出HOME變量,下面為正確方式  RUN [ "sh", "-c", "echo", "$HOME" ] RUN 產(chǎn)生的緩存在下一次構(gòu)建的適合是不會(huì)失效的,會(huì)被重用,可以使用--no-cache選擇,即docker build-no-cache,如此便不會(huì)緩存4.CMD  三種使用方式:CMD "executable","param1","param2"CMD "param1","param2"CMD command param1 param2 (shell form) 例子:CMD["nginx"] CMD指定在 Dockerfile 中只能使用一次,如果有多個(gè),則只有最后一個(gè)會(huì)生效。CMD的目的是為了在啟動(dòng)容器時(shí)提供一個(gè)默認(rèn)的命令執(zhí)行選項(xiàng)。如果用戶啟動(dòng)容器時(shí)指定了運(yùn)行的命令,則會(huì)覆蓋掉CMD指定的命令。CMD會(huì)在啟動(dòng)容器的時(shí)候執(zhí)行,build 時(shí)不執(zhí)行,而RUN只是在構(gòu)建鏡像的時(shí)候執(zhí)行,后續(xù)鏡像構(gòu)建完成之后,啟動(dòng)容器就與RUN無(wú)關(guān)了,這個(gè)初學(xué)者容易弄混這個(gè)概念,這里簡(jiǎn)單注解一下。  5.EXPOSE [...]  告訴docker服務(wù)端容器對(duì)外映射的本地端口,需要在docker run的使用使用-p或者-P選項(xiàng)生效  例子:EXPOSE 806.ENV  ENV   ENV =。。。  指定一個(gè)環(huán)節(jié)變量,會(huì)被后續(xù)RUN指令使用,并在容器運(yùn)行時(shí)保留  例子:ENV myname zxg     ENV myhome beijing     ENV myname="zxg" myhome=beijing  7.ADD  ADD ...  ADD復(fù)制本地主機(jī)文件、目錄或者遠(yuǎn)程文件URLS從并且添加到容器指定路徑中  支持通過(guò)Go的正則模式匹配,具體規(guī)則可參見(jiàn)Go filepath.Match  例子:ADD hom* /mydir/  #adds all files starting with ”hom“     ADD hom?.txt /mydir/ #?is replaced with any single character    ADD index.html /usr/share/nginx/html/index.html  注意如下:路徑必須是絕對(duì)路徑,如果 不存在,會(huì)自動(dòng)創(chuàng)建對(duì)應(yīng)目錄路徑必須是 Dockerfile 所在路徑的相對(duì)路徑如果是一個(gè)目錄,只會(huì)復(fù)制目錄下的內(nèi)容,而目錄本身則不會(huì)被復(fù)制8.COPY  COPY ...  COPY復(fù)制新文件或者目錄并且添加到容器指定路徑中,用法和ADD相同,唯一區(qū)別時(shí)不能指定遠(yuǎn)程文件URLS。9.ENTRYPOINT  ENTRYPOINT "executable","param1","param2"  ENTRYPOINT command param1 param2(shell form)    配置容器啟動(dòng)后執(zhí)行的命令,并且不可被 docker run 提供的參數(shù)覆蓋,而CMD是可以被覆蓋的。如果需要覆蓋,則可以使用docker run --entrypoint選項(xiàng)。    每個(gè) Dockerfile 中只能有一個(gè)ENTRYPOINT,當(dāng)指定多個(gè)時(shí),只有最后一個(gè)生效。    Exec form ENTRYPOINT 例子    通過(guò)ENTRYPOINT使用 exec form 方式設(shè)置穩(wěn)定的默認(rèn)命令和選項(xiàng),而使用CMD添加默認(rèn)之外經(jīng)常被改動(dòng)的選項(xiàng)。    FROM ubuntu    ENTRYPOINT ["top", "-b"]    CMD ["-c"]    通過(guò) Dockerfile 使用ENTRYPOINT展示前臺(tái)運(yùn)行 Apache 服務(wù)    FROM debian:stable    RUN apt-get update && apt-get install -y --force-yes apache2    EXPOSE 80 443    VOLUME ["/var/www", "/var/log/apache2", "/etc/apache2"]    ENTRYPOINT ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]    Shell form ENTRYPOINT 例子    這種方式會(huì)在/bin/sh -c中執(zhí)行,會(huì)忽略任何CMD或者docker run命令行選項(xiàng),為了確保docker stop能夠停止長(zhǎng)時(shí)間運(yùn)行ENTRYPOINT的容器,確保執(zhí)行的時(shí)候使用exec選項(xiàng)。    FROM ubuntu    ENTRYPOINT exec top -b    如果在ENTRYPOINT忘記使用exec選項(xiàng),則可以使用CMD補(bǔ)上:    FROM ubuntu    ENTRYPOINT top -b    CMD --ignored-param1 # --ignored-param2 ... --ignored-param3 ... 依此類推10.VOLUME   VOLUME ["/data"]  創(chuàng)建一個(gè)可以從本地主機(jī)或其他容器掛載的掛載點(diǎn),后續(xù)具體介紹11.USER  USER daemon  指定運(yùn)行容器時(shí)的用戶名或UID,后續(xù)RUN、CMD、ENTERPOINT也會(huì)使用指定用戶12.WORKDIR  WORKDIR /path/to/workdir  為后續(xù)的RUN、CMD、ENTRYPOINT指令配置工作目錄。可以使用多個(gè)WORKDIR指令,后續(xù)命令如果參數(shù)是相對(duì)路徑,則會(huì)基于之前命令指定的路徑  WORKDIR /a  WORKDIR b  WORKDIR c  RUN pwd  最終路徑是/a/b/c  WORKDIR指令可以在ENV設(shè)置變量之后調(diào)用環(huán)境變量:  ENV DIRPATH /path  WORKDIR $DIRPATH/$DIRNAME  最終路徑則為 /path/$DIRNAME 13.ONBUILD  ONBUILD [INSTRUCTION]  配置當(dāng)所創(chuàng)建的鏡像作為其他新創(chuàng)建鏡像的基礎(chǔ)鏡像時(shí),所執(zhí)行的操作指令  例如:Dockerfile 使用如下的內(nèi)容創(chuàng)建了鏡像image-A:    [...]    ONBUILD ADD . /app/src    ONBUILD RUN /usr/local/bin/python-build --dri /app/src    [...]

3.例子examples,做一個(gè)centos安裝了nginx及wget的鏡像

[root@web1 docker]# vim Dockerfile#this is docker file for centos-nginxFROM centosMAINTAINER zxg RUN yum install wget -yRUN rpm -ivh https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm N yum install nginx -y▽DD index.html /usr/share/nginx/html/index.htmlRUN echo "daemon off;">>/etc/nginx/nginx.confEXPOSE 80CMD ["nginx"]

4.使用build命令制作鏡像

1)build命令說(shuō)明

$ docker build --helpUsage: docker build [OPTIONS] PATH | URL | -Build a new image from the source code at PATH --force-rm=false Always remove intermediate containers, even after unsuccessful builds # 移除過(guò)渡容器,即使構(gòu)建失敗 --no-cache=false Do not use cache when building the image # 不實(shí)用 cache -q, --quiet=false Suppress the verbose output generated by the containers --rm=true Remove intermediate containers after a successful build # 構(gòu)建成功后移除過(guò)渡層容器 -t, --tag="" Repository name (and optionally a tag) to be applied to the resulting image in case of success

2)制作鏡像

docker build -t zxg/nginx1 .

整個(gè)過(guò)程還挺長(zhǎng),所以折疊了,可以點(diǎn)開(kāi)看一下

[root@web1 docker]# docker build -t zxg/nginx1 .Sending build context to Docker daemon 3.072 kBStep 1/9 : FROM centos ---> 9f38484d220fStep 2/9 : MAINTAINER zxg ---> Using cache ---> 35983aa687edStep 3/9 : RUN yum install wget -y ---> Using cache ---> efb8205fc8d2Step 4/9 : RUN rpm -ivh https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm ---> Running in 56c5812e494fwarning: /var/tmp/rpm-tmp.pS5KO3: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEYRetrieving https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpmPreparing... ########################################Updating / installing...epel-release-7-11 ######################################## ---> cf40357c60bbRemoving intermediate container 56c5812e494fStep 5/9 : RUN yum install nginx -y ---> Running in 36ebe7b47657Loaded plugins: fastestmirror, ovlLoading mirror speeds from cached hostfile * base: mirrors.tuna.tsinghua.edu.cn * epel: mirrors.tuna.tsinghua.edu.cn * extras: mirrors.aliyun.com * updates: mirrors.huaweicloud.comhttps://hkg.mirror.rackspace.com/epel/7/x86_64/repodata/192b605ef6d0f773ad6162832c60509e1bc0817e28662ea77340078287b3b4d8-updateinfo.xml.bz2: [Errno 14] HTTPS Error 404 - Not FoundTrying other mirror.To address this issue please refer to the below wiki article https://wiki.centos.org/yum-errorsIf above article doesn't help to resolve this issue please use https://bugs.centos.org/.https://mirrors.njupt.edu.cn/epel/7/x86_64/repodata/dc10637460e531277a1cd82574de2dde2637fd3a9e90cd0282e9436d3a95b91d-primary.sqlite.bz2: [Errno 14] HTTPS Error 404 - Not FoundTrying other mirror.http://fedora.cs.nctu.edu.tw/epel/7/x86_64/repodata/dc10637460e531277a1cd82574de2dde2637fd3a9e90cd0282e9436d3a95b91d-primary.sqlite.bz2: [Errno 14] HTTP Error 404 - Not FoundTrying other mirror.Resolving Dependencies--> Running transaction check---> Package nginx.x86_64 1:1.12.2-3.el7 will be installed--> Processing Dependency: nginx-all-modules = 1:1.12.2-3.el7 for package: 1:nginx-1.12.2-3.el7.x86_64--> Processing Dependency: nginx-filesystem = 1:1.12.2-3.el7 for package: 1:nginx-1.12.2-3.el7.x86_64--> Processing Dependency: nginx-filesystem for package: 1:nginx-1.12.2-3.el7.x86_64--> Processing Dependency: openssl for package: 1:nginx-1.12.2-3.el7.x86_64--> Processing Dependency: libprofiler.so.0()(64bit) for package: 1:nginx-1.12.2-3.el7.x86_64--> Running transaction check---> Package gperftools-libs.x86_64 0:2.6.1-1.el7 will be installed---> Package nginx-all-modules.noarch 1:1.12.2-3.el7 will be installed--> Processing Dependency: nginx-mod-http-geoip = 1:1.12.2-3.el7 for package: 1:nginx-all-modules-1.12.2-3.el7.noarch--> Processing Dependency: nginx-mod-http-image-filter = 1:1.12.2-3.el7 for package: 1:nginx-all-modules-1.12.2-3.el7.noarch--> Processing Dependency: nginx-mod-http-perl = 1:1.12.2-3.el7 for package: 1:nginx-all-modules-1.12.2-3.el7.noarch--> Processing Dependency: nginx-mod-http-xslt-filter = 1:1.12.2-3.el7 for package: 1:nginx-all-modules-1.12.2-3.el7.noarch--> Processing Dependency: nginx-mod-mail = 1:1.12.2-3.el7 for package: 1:nginx-all-modules-1.12.2-3.el7.noarch--> Processing Dependency: nginx-mod-stream = 1:1.12.2-3.el7 for package: 1:nginx-all-modules-1.12.2-3.el7.noarch---> Package nginx-filesystem.noarch 1:1.12.2-3.el7 will be installed---> Package openssl.x86_64 1:1.0.2k-16.el7_6.1 will be installed--> Processing Dependency: openssl-libs(x86-64) = 1:1.0.2k-16.el7_6.1 for package: 1:openssl-1.0.2k-16.el7_6.1.x86_64--> Processing Dependency: make for package: 1:openssl-1.0.2k-16.el7_6.1.x86_64--> Running transaction check---> Package make.x86_64 1:3.82-23.el7 will be installed---> Package nginx-mod-http-geoip.x86_64 1:1.12.2-3.el7 will be installed--> Processing Dependency: GeoIP for package: 1:nginx-mod-http-geoip-1.12.2-3.el7.x86_64--> Processing Dependency: libGeoIP.so.1()(64bit) for package: 1:nginx-mod-http-geoip-1.12.2-3.el7.x86_64---> Package nginx-mod-http-image-filter.x86_64 1:1.12.2-3.el7 will be installed--> Processing Dependency: gd for package: 1:nginx-mod-http-image-filter-1.12.2-3.el7.x86_64--> Processing Dependency: libgd.so.2()(64bit) for package: 1:nginx-mod-http-image-filter-1.12.2-3.el7.x86_64---> Package nginx-mod-http-perl.x86_64 1:1.12.2-3.el7 will be installed--> Processing Dependency: perl >= 5.006001 for package: 1:nginx-mod-http-perl-1.12.2-3.el7.x86_64--> Processing Dependency: perl(:MODULE_COMPAT_5.16.3) for package: 1:nginx-mod-http-perl-1.12.2-3.el7.x86_64--> Processing Dependency: perl(Exporter) for package: 1:nginx-mod-http-perl-1.12.2-3.el7.x86_64--> Processing Dependency: perl(XSLoader) for package: 1:nginx-mod-http-perl-1.12.2-3.el7.x86_64--> Processing Dependency: perl(constant) for package: 1:nginx-mod-http-perl-1.12.2-3.el7.x86_64--> Processing Dependency: perl(strict) for package: 1:nginx-mod-http-perl-1.12.2-3.el7.x86_64--> Processing Dependency: perl(warnings) for package: 1:nginx-mod-http-perl-1.12.2-3.el7.x86_64--> Processing Dependency: libperl.so()(64bit) for package: 1:nginx-mod-http-perl-1.12.2-3.el7.x86_64---> Package nginx-mod-http-xslt-filter.x86_64 1:1.12.2-3.el7 will be installed--> Processing Dependency: libxslt.so.1(LIBXML2_1.0.11)(64bit) for package: 1:nginx-mod-http-xslt-filter-1.12.2-3.el7.x86_64--> Processing Dependency: libxslt.so.1(LIBXML2_1.0.18)(64bit) for package: 1:nginx-mod-http-xslt-filter-1.12.2-3.el7.x86_64--> Processing Dependency: libexslt.so.0()(64bit) for package: 1:nginx-mod-http-xslt-filter-1.12.2-3.el7.x86_64--> Processing Dependency: libxslt.so.1()(64bit) for package: 1:nginx-mod-http-xslt-filter-1.12.2-3.el7.x86_64---> Package nginx-mod-mail.x86_64 1:1.12.2-3.el7 will be installed---> Package nginx-mod-stream.x86_64 1:1.12.2-3.el7 will be installed---> Package openssl-libs.x86_64 1:1.0.2k-16.el7 will be updated---> Package openssl-libs.x86_64 1:1.0.2k-16.el7_6.1 will be an update--> Running transaction check---> Package GeoIP.x86_64 0:1.5.0-13.el7 will be installed---> Package gd.x86_64 0:2.0.35-26.el7 will be installed--> Processing Dependency: libpng15.so.15(PNG15_0)(64bit) for package: gd-2.0.35-26.el7.x86_64--> Processing Dependency: libjpeg.so.62(LIBJPEG_6.2)(64bit) for package: gd-2.0.35-26.el7.x86_64--> Processing Dependency: libpng15.so.15()(64bit) for package: gd-2.0.35-26.el7.x86_64--> Processing Dependency: libjpeg.so.62()(64bit) for package: gd-2.0.35-26.el7.x86_64--> Processing Dependency: libfreetype.so.6()(64bit) for package: gd-2.0.35-26.el7.x86_64--> Processing Dependency: libfontconfig.so.1()(64bit) for package: gd-2.0.35-26.el7.x86_64--> Processing Dependency: libXpm.so.4()(64bit) for package: gd-2.0.35-26.el7.x86_64--> Processing Dependency: libX11.so.6()(64bit) for package: gd-2.0.35-26.el7.x86_64---> Package libxslt.x86_64 0:1.1.28-5.el7 will be installed---> Package perl.x86_64 4:5.16.3-294.el7_6 will be installed--> Processing Dependency: perl(Socket) >= 1.3 for package: 4:perl-5.16.3-294.el7_6.x86_64--> Processing Dependency: perl(Scalar::Util) >= 1.10 for package: 4:perl-5.16.3-294.el7_6.x86_64--> Processing Dependency: perl-macros for package: 4:perl-5.16.3-294.el7_6.x86_64--> Processing Dependency: perl(threads::shared) for package: 4:perl-5.16.3-294.el7_6.x86_64--> Processing Dependency: perl(threads) for package: 4:perl-5.16.3-294.el7_6.x86_64--> Processing Dependency: perl(Time::Local) for package: 4:perl-5.16.3-294.el7_6.x86_64--> Processing Dependency: perl(Time::HiRes) for package: 4:perl-5.16.3-294.el7_6.x86_64--> Processing Dependency: perl(Storable) for package: 4:perl-5.16.3-294.el7_6.x86_64--> Processing Dependency: perl(Socket) for package: 4:perl-5.16.3-294.el7_6.x86_64--> Processing Dependency: perl(Scalar::Util) for package: 4:perl-5.16.3-294.el7_6.x86_64--> Processing Dependency: perl(Pod::Simple::XHTML) for package: 4:perl-5.16.3-294.el7_6.x86_64--> Processing Dependency: perl(Pod::Simple::Search) for package: 4:perl-5.16.3-294.el7_6.x86_64--> Processing Dependency: perl(Getopt::Long) for package: 4:perl-5.16.3-294.el7_6.x86_64--> Processing Dependency: perl(Filter::Util::Call) for package: 4:perl-5.16.3-294.el7_6.x86_64--> Processing Dependency: perl(File::Temp) for package: 4:perl-5.16.3-294.el7_6.x86_64--> Processing Dependency: perl(File::Spec::Unix) for package: 4:perl-5.16.3-294.el7_6.x86_64--> Processing Dependency: perl(File::Spec::Functions) for package: 4:perl-5.16.3-294.el7_6.x86_64--> Processing Dependency: perl(File::Spec) for package: 4:perl-5.16.3-294.el7_6.x86_64--> Processing Dependency: perl(File::Path) for package: 4:perl-5.16.3-294.el7_6.x86_64--> Processing Dependency: perl(Cwd) for package: 4:perl-5.16.3-294.el7_6.x86_64--> Processing Dependency: perl(Carp) for package: 4:perl-5.16.3-294.el7_6.x86_64---> Package perl-Exporter.noarch 0:5.68-3.el7 will be installed---> Package perl-constant.noarch 0:1.27-2.el7 will be installed---> Package perl-libs.x86_64 4:5.16.3-294.el7_6 will be installed--> Running transaction check---> Package fontconfig.x86_64 0:2.13.0-4.3.el7 will be installed--> Processing Dependency: fontpackages-filesystem for package: fontconfig-2.13.0-4.3.el7.x86_64--> Processing Dependency: dejavu-sans-fonts for package: fontconfig-2.13.0-4.3.el7.x86_64---> Package freetype.x86_64 0:2.8-12.el7_6.1 will be installed---> Package libX11.x86_64 0:1.6.5-2.el7 will be installed--> Processing Dependency: libX11-common >= 1.6.5-2.el7 for package: libX11-1.6.5-2.el7.x86_64--> Processing Dependency: libxcb.so.1()(64bit) for package: libX11-1.6.5-2.el7.x86_64---> Package libXpm.x86_64 0:3.5.12-1.el7 will be installed---> Package libjpeg-turbo.x86_64 0:1.2.90-6.el7 will be installed---> Package libpng.x86_64 2:1.5.13-7.el7_2 will be installed---> Package perl-Carp.noarch 0:1.26-244.el7 will be installed---> Package perl-File-Path.noarch 0:2.09-2.el7 will be installed---> Package perl-File-Temp.noarch 0:0.23.01-3.el7 will be installed---> Package perl-Filter.x86_64 0:1.49-3.el7 will be installed---> Package perl-Getopt-Long.noarch 0:2.40-3.el7 will be installed--> Processing Dependency: perl(Pod::Usage) >= 1.14 for package: perl-Getopt-Long-2.40-3.el7.noarch--> Processing Dependency: perl(Text::ParseWords) for package: perl-Getopt-Long-2.40-3.el7.noarch---> Package perl-PathTools.x86_64 0:3.40-5.el7 will be installed---> Package perl-Pod-Simple.noarch 1:3.28-4.el7 will be installed--> Processing Dependency: perl(Pod::Escapes) >= 1.04 for package: 1:perl-Pod-Simple-3.28-4.el7.noarch--> Processing Dependency: perl(Encode) for package: 1:perl-Pod-Simple-3.28-4.el7.noarch---> Package perl-Scalar-List-Utils.x86_64 0:1.27-248.el7 will be installed---> Package perl-Socket.x86_64 0:2.010-4.el7 will be installed---> Package perl-Storable.x86_64 0:2.45-3.el7 will be installed---> Package perl-Time-HiRes.x86_64 4:1.9725-3.el7 will be installed---> Package perl-Time-Local.noarch 0:1.2300-2.el7 will be installed---> Package perl-macros.x86_64 4:5.16.3-294.el7_6 will be installed---> Package perl-threads.x86_64 0:1.87-4.el7 will be installed---> Package perl-threads-shared.x86_64 0:1.43-6.el7 will be installed--> Running transaction check---> Package dejavu-sans-fonts.noarch 0:2.33-6.el7 will be installed--> Processing Dependency: dejavu-fonts-common = 2.33-6.el7 for package: dejavu-sans-fonts-2.33-6.el7.noarch---> Package fontpackages-filesystem.noarch 0:1.44-8.el7 will be installed---> Package libX11-common.noarch 0:1.6.5-2.el7 will be installed---> Package libxcb.x86_64 0:1.13-1.el7 will be installed--> Processing Dependency: libXau.so.6()(64bit) for package: libxcb-1.13-1.el7.x86_64---> Package perl-Encode.x86_64 0:2.51-7.el7 will be installed---> Package perl-Pod-Escapes.noarch 1:1.04-294.el7_6 will be installed---> Package perl-Pod-Usage.noarch 0:1.63-3.el7 will be installed--> Processing Dependency: perl(Pod::Text) >= 3.15 for package: perl-Pod-Usage-1.63-3.el7.noarch--> Processing Dependency: perl-Pod-Perldoc for package: perl-Pod-Usage-1.63-3.el7.noarch---> Package perl-Text-ParseWords.noarch 0:3.29-4.el7 will be installed--> Running transaction check---> Package dejavu-fonts-common.noarch 0:2.33-6.el7 will be installed---> Package libXau.x86_64 0:1.0.8-2.1.el7 will be installed---> Package perl-Pod-Perldoc.noarch 0:3.20-4.el7 will be installed--> Processing Dependency: perl(parent) for package: perl-Pod-Perldoc-3.20-4.el7.noarch--> Processing Dependency: perl(HTTP::Tiny) for package: perl-Pod-Perldoc-3.20-4.el7.noarch--> Processing Dependency: groff-base for package: perl-Pod-Perldoc-3.20-4.el7.noarch---> Package perl-podlators.noarch 0:2.5.1-3.el7 will be installed--> Running transaction check---> Package groff-base.x86_64 0:1.22.2-8.el7 will be installed---> Package perl-HTTP-Tiny.noarch 0:0.033-3.el7 will be installed---> Package perl-parent.noarch 1:0.225-244.el7 will be installed--> Finished Dependency ResolutionDependencies Resolved================================================================================ Package Arch Version Repository Size================================================================================Installing: nginx x86_64 1:1.12.2-3.el7 epel 531 kInstalling for dependencies: GeoIP x86_64 1.5.0-13.el7 base 1.5 M dejavu-fonts-common noarch 2.33-6.el7 base 64 k dejavu-sans-fonts noarch 2.33-6.el7 base 1.4 M fontconfig x86_64 2.13.0-4.3.el7 base 254 k fontpackages-filesystem noarch 1.44-8.el7 base 9.9 k freetype x86_64 2.8-12.el7_6.1 updates 380 k gd x86_64 2.0.35-26.el7 base 146 k gperftools-libs x86_64 2.6.1-1.el7 base 272 k groff-base x86_64 1.22.2-8.el7 base 942 k libX11 x86_64 1.6.5-2.el7 base 606 k libX11-common noarch 1.6.5-2.el7 base 164 k libXau x86_64 1.0.8-2.1.el7 base 29 k libXpm x86_64 3.5.12-1.el7 base 55 k libjpeg-turbo x86_64 1.2.90-6.el7 base 134 k libpng x86_64 2:1.5.13-7.el7_2 base 213 k libxcb x86_64 1.13-1.el7 base 214 k libxslt x86_64 1.1.28-5.el7 base 242 k make x86_64 1:3.82-23.el7 base 420 k nginx-all-modules noarch 1:1.12.2-3.el7 epel 16 k nginx-filesystem noarch 1:1.12.2-3.el7 epel 17 k nginx-mod-http-geoip x86_64 1:1.12.2-3.el7 epel 23 k nginx-mod-http-image-filter x86_64 1:1.12.2-3.el7 epel 27 k nginx-mod-http-perl x86_64 1:1.12.2-3.el7 epel 36 k nginx-mod-http-xslt-filter x86_64 1:1.12.2-3.el7 epel 26 k nginx-mod-mail x86_64 1:1.12.2-3.el7 epel 54 k nginx-mod-stream x86_64 1:1.12.2-3.el7 epel 76 k openssl x86_64 1:1.0.2k-16.el7_6.1 updates 493 k perl x86_64 4:5.16.3-294.el7_6 updates 8.0 M perl-Carp noarch 1.26-244.el7 base 19 k perl-Encode x86_64 2.51-7.el7 base 1.5 M perl-Exporter noarch 5.68-3.el7 base 28 k perl-File-Path noarch 2.09-2.el7 base 26 k perl-File-Temp noarch 0.23.01-3.el7 base 56 k perl-Filter x86_64 1.49-3.el7 base 76 k perl-Getopt-Long noarch 2.40-3.el7 base 56 k perl-HTTP-Tiny noarch 0.033-3.el7 base 38 k perl-PathTools x86_64 3.40-5.el7 base 82 k perl-Pod-Escapes noarch 1:1.04-294.el7_6 updates 51 k perl-Pod-Perldoc noarch 3.20-4.el7 base 87 k perl-Pod-Simple noarch 1:3.28-4.el7 base 216 k perl-Pod-Usage noarch 1.63-3.el7 base 27 k perl-Scalar-List-Utils x86_64 1.27-248.el7 base 36 k perl-Socket x86_64 2.010-4.el7 base 49 k perl-Storable x86_64 2.45-3.el7 base 77 k perl-Text-ParseWords noarch 3.29-4.el7 base 14 k perl-Time-HiRes x86_64 4:1.9725-3.el7 base 45 k perl-Time-Local noarch 1.2300-2.el7 base 24 k perl-constant noarch 1.27-2.el7 base 19 k perl-libs x86_64 4:5.16.3-294.el7_6 updates 688 k perl-macros x86_64 4:5.16.3-294.el7_6 updates 44 k perl-parent noarch 1:0.225-244.el7 base 12 k perl-podlators noarch 2.5.1-3.el7 base 112 k perl-threads x86_64 1.87-4.el7 base 49 k perl-threads-shared x86_64 1.43-6.el7 base 39 kUpdating for dependencies: openssl-libs x86_64 1:1.0.2k-16.el7_6.1 updates 1.2 MTransaction Summary================================================================================Install 1 Package (+54 Dependent packages)Upgrade ( 1 Dependent package)Total download size: 21 MDownloading packages:Delta RPMs disabled because /usr/bin/applydeltarpm not installed.warning: /var/cache/yum/x86_64/7/epel/packages/nginx-1.12.2-3.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEYPublic key for nginx-1.12.2-3.el7.x86_64.rpm is not installed--------------------------------------------------------------------------------Total 868 kB/s | 21 MB 00:24 Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7Importing GPG key 0x352C64E5: Userid : "Fedora EPEL (7) " Fingerprint: 91e9 7d7c 4a5e 96f1 7f3e 888f 6a2f aea2 352c 64e5 Package : epel-release-7-11.noarch (installed) From : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7Running transaction checkRunning transaction testTransaction test succeededRunning transactionWarning: RPMDB altered outside of yum. Updating : 1:openssl-libs-1.0.2k-16.el7_6.1.x86_64 1/57 Installing : fontpackages-filesystem-1.44-8.el7.noarch 2/57 Installing : 2:libpng-1.5.13-7.el7_2.x86_64 3/57 Installing : freetype-2.8-12.el7_6.1.x86_64 4/57 Installing : dejavu-fonts-common-2.33-6.el7.noarch 5/57 Installing : dejavu-sans-fonts-2.33-6.el7.noarch 6/57 Installing : fontconfig-2.13.0-4.3.el7.x86_64 7/57 Installing : 1:nginx-filesystem-1.12.2-3.el7.noarch 8/57 Installing : libX11-common-1.6.5-2.el7.noarch 9/57 Installing : gperftools-libs-2.6.1-1.el7.x86_64 10/57 Installing : libXau-1.0.8-2.1.el7.x86_64 11/57 Installing : libxcb-1.13-1.el7.x86_64 12/57 Installing : libX11-1.6.5-2.el7.x86_64 13/57 Installing : libXpm-3.5.12-1.el7.x86_64 14/57 Installing : libxslt-1.1.28-5.el7.x86_64 15/57 Installing : groff-base-1.22.2-8.el7.x86_64 16/57 Installing : 1:perl-parent-0.225-244.el7.noarch 17/57 Installing : perl-HTTP-Tiny-0.033-3.el7.noarch 18/57 Installing : perl-podlators-2.5.1-3.el7.noarch 19/57 Installing : perl-Pod-Perldoc-3.20-4.el7.noarch 20/57 Installing : 1:perl-Pod-Escapes-1.04-294.el7_6.noarch 21/57 Installing : perl-Text-ParseWords-3.29-4.el7.noarch 22/57 Installing : perl-Encode-2.51-7.el7.x86_64 23/57 Installing : perl-Pod-Usage-1.63-3.el7.noarch 24/57 Installing : 4:perl-libs-5.16.3-294.el7_6.x86_64 25/57 Installing : 4:perl-macros-5.16.3-294.el7_6.x86_64 26/57 Installing : 4:perl-Time-HiRes-1.9725-3.el7.x86_64 27/57 Installing : perl-Exporter-5.68-3.el7.noarch 28/57 Installing : perl-constant-1.27-2.el7.noarch 29/57 Installing : perl-Time-Local-1.2300-2.el7.noarch 30/57 Installing : perl-Carp-1.26-244.el7.noarch 31/57 Installing : perl-Storable-2.45-3.el7.x86_64 32/57 Installing : perl-PathTools-3.40-5.el7.x86_64 33/57 Installing : perl-Scalar-List-Utils-1.27-248.el7.x86_64 34/57 Installing : perl-File-Temp-0.23.01-3.el7.noarch 35/57 Installing : perl-File-Path-2.09-2.el7.noarch 36/57 Installing : perl-threads-shared-1.43-6.el7.x86_64 37/57 Installing : perl-threads-1.87-4.el7.x86_64 38/57 Installing : perl-Filter-1.49-3.el7.x86_64 39/57 Installing : perl-Socket-2.010-4.el7.x86_64 40/57 Installing : 1:perl-Pod-Simple-3.28-4.el7.noarch 41/57 Installing : perl-Getopt-Long-2.40-3.el7.noarch 42/57 Installing : 4:perl-5.16.3-294.el7_6.x86_64 43/57 Installing : GeoIP-1.5.0-13.el7.x86_64 44/57 Installing : libjpeg-turbo-1.2.90-6.el7.x86_64 45/57 Installing : gd-2.0.35-26.el7.x86_64 46/57 Installing : 1:make-3.82-23.el7.x86_64 47/57 Installing : 1:openssl-1.0.2k-16.el7_6.1.x86_64 48/57 Installing : 1:nginx-mod-http-image-filter-1.12.2-3.el7.x86_64 49/57 Installing : 1:nginx-mod-mail-1.12.2-3.el7.x86_64 50/57 Installing : 1:nginx-mod-stream-1.12.2-3.el7.x86_64 51/57 Installing : 1:nginx-mod-http-xslt-filter-1.12.2-3.el7.x86_64 52/57 Installing : 1:nginx-mod-http-perl-1.12.2-3.el7.x86_64 53/57 Installing : 1:nginx-mod-http-geoip-1.12.2-3.el7.x86_64 54/57 Installing : 1:nginx-all-modules-1.12.2-3.el7.noarch 55/57 Installing : 1:nginx-1.12.2-3.el7.x86_64 56/57 Cleanup : 1:openssl-libs-1.0.2k-16.el7.x86_64 57/57 Verifying : 1:nginx-all-modules-1.12.2-3.el7.noarch 1/57 Verifying : fontconfig-2.13.0-4.3.el7.x86_64 2/57 Verifying : perl-HTTP-Tiny-0.033-3.el7.noarch 3/57 Verifying : 1:nginx-mod-http-image-filter-1.12.2-3.el7.x86_64 4/57 Verifying : perl-threads-shared-1.43-6.el7.x86_64 5/57 Verifying : 4:perl-Time-HiRes-1.9725-3.el7.x86_64 6/57 Verifying : 1:perl-Pod-Escapes-1.04-294.el7_6.noarch 7/57 Verifying : 1:make-3.82-23.el7.x86_64 8/57 Verifying : perl-Exporter-5.68-3.el7.noarch 9/57 Verifying : perl-constant-1.27-2.el7.noarch 10/57 Verifying : perl-PathTools-3.40-5.el7.x86_64 11/57 Verifying : 1:nginx-1.12.2-3.el7.x86_64 12/57 Verifying : 2:libpng-1.5.13-7.el7_2.x86_64 13/57 Verifying : 1:nginx-mod-mail-1.12.2-3.el7.x86_64 14/57 Verifying : 1:nginx-mod-stream-1.12.2-3.el7.x86_64 15/57 Verifying : dejavu-fonts-common-2.33-6.el7.noarch 16/57 Verifying : fontpackages-filesystem-1.44-8.el7.noarch 17/57 Verifying : libjpeg-turbo-1.2.90-6.el7.x86_64 18/57 Verifying : 1:perl-parent-0.225-244.el7.noarch 19/57 Verifying : 1:nginx-mod-http-xslt-filter-1.12.2-3.el7.x86_64 20/57 Verifying : GeoIP-1.5.0-13.el7.x86_64 21/57 Verifying : 4:perl-libs-5.16.3-294.el7_6.x86_64 22/57 Verifying : groff-base-1.22.2-8.el7.x86_64 23/57 Verifying : perl-File-Temp-0.23.01-3.el7.noarch 24/57 Verifying : 1:perl-Pod-Simple-3.28-4.el7.noarch 25/57 Verifying : perl-Getopt-Long-2.40-3.el7.noarch 26/57 Verifying : perl-Time-Local-1.2300-2.el7.noarch 27/57 Verifying : libxcb-1.13-1.el7.x86_64 28/57 Verifying : 4:perl-macros-5.16.3-294.el7_6.x86_64 29/57 Verifying : 4:perl-5.16.3-294.el7_6.x86_64 30/57 Verifying : libXpm-3.5.12-1.el7.x86_64 31/57 Verifying : 1:nginx-mod-http-perl-1.12.2-3.el7.x86_64 32/57 Verifying : 1:openssl-1.0.2k-16.el7_6.1.x86_64 33/57 Verifying : perl-Carp-1.26-244.el7.noarch 34/57 Verifying : libxslt-1.1.28-5.el7.x86_64 35/57 Verifying : libX11-1.6.5-2.el7.x86_64 36/57 Verifying : perl-Storable-2.45-3.el7.x86_64 37/57 Verifying : dejavu-sans-fonts-2.33-6.el7.noarch 38/57 Verifying : perl-Scalar-List-Utils-1.27-248.el7.x86_64 39/57 Verifying : gd-2.0.35-26.el7.x86_64 40/57 Verifying : 1:nginx-mod-http-geoip-1.12.2-3.el7.x86_64 41/57 Verifying : perl-Pod-Usage-1.63-3.el7.noarch 42/57 Verifying : perl-Encode-2.51-7.el7.x86_64 43/57 Verifying : perl-Pod-Perldoc-3.20-4.el7.noarch 44/57 Verifying : perl-podlators-2.5.1-3.el7.noarch 45/57 Verifying : libXau-1.0.8-2.1.el7.x86_64 46/57 Verifying : perl-File-Path-2.09-2.el7.noarch 47/57 Verifying : perl-threads-1.87-4.el7.x86_64 48/57 Verifying : gperftools-libs-2.6.1-1.el7.x86_64 49/57 Verifying : libX11-common-1.6.5-2.el7.noarch 50/57 Verifying : perl-Filter-1.49-3.el7.x86_64 51/57 Verifying : freetype-2.8-12.el7_6.1.x86_64 52/57 Verifying : perl-Text-ParseWords-3.29-4.el7.noarch 53/57 Verifying : perl-Socket-2.010-4.el7.x86_64 54/57 Verifying : 1:nginx-filesystem-1.12.2-3.el7.noarch 55/57 Verifying : 1:openssl-libs-1.0.2k-16.el7_6.1.x86_64 56/57 Verifying : 1:openssl-libs-1.0.2k-16.el7.x86_64 57/57 Installed: nginx.x86_64 1:1.12.2-3.el7 Dependency Installed: GeoIP.x86_64 0:1.5.0-13.el7 dejavu-fonts-common.noarch 0:2.33-6.el7 dejavu-sans-fonts.noarch 0:2.33-6.el7 fontconfig.x86_64 0:2.13.0-4.3.el7 fontpackages-filesystem.noarch 0:1.44-8.el7 freetype.x86_64 0:2.8-12.el7_6.1 gd.x86_64 0:2.0.35-26.el7 gperftools-libs.x86_64 0:2.6.1-1.el7 groff-base.x86_64 0:1.22.2-8.el7 libX11.x86_64 0:1.6.5-2.el7 libX11-common.noarch 0:1.6.5-2.el7 libXau.x86_64 0:1.0.8-2.1.el7 libXpm.x86_64 0:3.5.12-1.el7 libjpeg-turbo.x86_64 0:1.2.90-6.el7 libpng.x86_64 2:1.5.13-7.el7_2 libxcb.x86_64 0:1.13-1.el7 libxslt.x86_64 0:1.1.28-5.el7 make.x86_64 1:3.82-23.el7 nginx-all-modules.noarch 1:1.12.2-3.el7 nginx-filesystem.noarch 1:1.12.2-3.el7 nginx-mod-http-geoip.x86_64 1:1.12.2-3.el7 nginx-mod-http-image-filter.x86_64 1:1.12.2-3.el7 nginx-mod-http-perl.x86_64 1:1.12.2-3.el7 nginx-mod-http-xslt-filter.x86_64 1:1.12.2-3.el7 nginx-mod-mail.x86_64 1:1.12.2-3.el7 nginx-mod-stream.x86_64 1:1.12.2-3.el7 openssl.x86_64 1:1.0.2k-16.el7_6.1 perl.x86_64 4:5.16.3-294.el7_6 perl-Carp.noarch 0:1.26-244.el7 perl-Encode.x86_64 0:2.51-7.el7 perl-Exporter.noarch 0:5.68-3.el7 perl-File-Path.noarch 0:2.09-2.el7 perl-File-Temp.noarch 0:0.23.01-3.el7 perl-Filter.x86_64 0:1.49-3.el7 perl-Getopt-Long.noarch 0:2.40-3.el7 perl-HTTP-Tiny.noarch 0:0.033-3.el7 perl-PathTools.x86_64 0:3.40-5.el7 perl-Pod-Escapes.noarch 1:1.04-294.el7_6 perl-Pod-Perldoc.noarch 0:3.20-4.el7 perl-Pod-Simple.noarch 1:3.28-4.el7 perl-Pod-Usage.noarch 0:1.63-3.el7 perl-Scalar-List-Utils.x86_64 0:1.27-248.el7 perl-Socket.x86_64 0:2.010-4.el7 perl-Storable.x86_64 0:2.45-3.el7 perl-Text-ParseWords.noarch 0:3.29-4.el7 perl-Time-HiRes.x86_64 4:1.9725-3.el7 perl-Time-Local.noarch 0:1.2300-2.el7 perl-constant.noarch 0:1.27-2.el7 perl-libs.x86_64 4:5.16.3-294.el7_6 perl-macros.x86_64 4:5.16.3-294.el7_6 perl-parent.noarch 1:0.225-244.el7 perl-podlators.noarch 0:2.5.1-3.el7 perl-threads.x86_64 0:1.87-4.el7 perl-threads-shared.x86_64 0:1.43-6.el7 Dependency Updated: openssl-libs.x86_64 1:1.0.2k-16.el7_6.1 Complete! ---> 996824f87698Removing intermediate container 36ebe7b47657Step 6/9 : ADD index.html /usr/share/nginx/html/index.html ---> a21387c003a7Removing intermediate container 74dfd64941b1Step 7/9 : RUN echo "daemon off;">>/etc/nginx/nginx.conf ---> Running in bd60f92d877e ---> 3b20cd6163a8Removing intermediate container bd60f92d877eStep 8/9 : EXPOSE 80 ---> Running in 54e388a3fd21 ---> 2aeecbaba79bRemoving intermediate container 54e388a3fd21Step 9/9 : CMD nginx ---> Running in 32d4b23b050c ---> 3babdf3c6c6dRemoving intermediate container 32d4b23b050cSuccessfully built 3babdf3c6c6d

5.驗(yàn)證一下,并用curl測(cè)試

[root@web1 docker]# docker run -d --name my_nginx1 zxg/nginx1 #后臺(tái)運(yùn)行整個(gè)容器751a8f9dda48c034d40b8855b3dd6c7aaf785eeaa9ae404c5eb3c0271e434f50[root@web1 docker]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES751a8f9dda48 zxg/nginx1 "nginx" About a minute ago Up About a minute 80/tcp my_nginx1[root@web1 docker]# docker exec -it my_nginx1 bash #進(jìn)入容器[root@751a8f9dda48 /]# cat /usr/share/nginx/html/index.html #查看文件是否添加到容器this is docker-centos7-nginx1[root@751a8f9dda48 /]# cat /etc/nginx/nginx.conf # For more information on configuration, see:# * Official English Documentation: http://nginx.org/en/docs/# * Official Russian Documentation: http://nginx.org/ru/docs/user nginx;worker_processes auto;error_log /var/log/nginx/error.log;pid /run/nginx.pid;# Load dynamic modules. See /usr/share/nginx/README.dynamic.include /usr/share/nginx/modules/*.conf;events { worker_connections 1024;}http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/*.conf; server { listen 80 default_server; listen [::]:80 default_server; server_name _; root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }# Settings for a TLS enabled server.## server {# listen 443 ssl http2 default_server;# listen [::]:443 ssl http2 default_server;# server_name _;# root /usr/share/nginx/html;## ssl_certificate "/etc/pki/nginx/server.crt";# ssl_certificate_key "/etc/pki/nginx/private/server.key";# ssl_session_cache shared:SSL:1m;# ssl_session_timeout 10m;# ssl_ciphers HIGH:!aNULL:!MD5;# ssl_prefer_server_ciphers on;## # Load configuration files for the default server block.# include /etc/nginx/default.d/*.conf;## location / {# }## error_page 404 /404.html;# location = /40x.html {# }## error_page 500 502 503 504 /50x.html;# location = /50x.html {# }# }}daemon off;[root@751a8f9dda48 /]# exitexit[root@web1 docker]# [root@751a8f9dda48 html]# curl 127.0.0.1this is docker-centos7-nginx1[root@751a8f9dda48 html]#[root@web1 ~]# docker inspect my_nginx1 |grep IPAddress "SecondaryIPAddresses": null, "IPAddress": "172.17.0.2", "IPAddress": "172.17.0.2",[root@web1 ~]# curl 172.17.0.2this is docker-centos7-nginx1[root@web1 ~]#

總結(jié)

以上是生活随笔為你收集整理的dockerfile中的run_Docker3-Dockerfile创建镜像的方法(推荐docker file这种方法)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。