Docker3-Dockerfile创建镜像的方法(推荐docker file这种方法)
一、镜像制作的方法
1、本地导入导出镜像
请参考:Docker 架构原理及简单使用
导出:docker save nginx >/tmp/nginx.tar.gz
导入:docker load </tmp/nginx.tar.gz
2、docker commit 命令创建镜像副本
请参考:Docker docker commit方法镜像制作
3、docker file
前面两种方法已经介绍过了,这里介绍docker file,生成环境推荐使用这种方法
二、docker file方法制作镜像
1、什么是docker file
用来全自动构建镜像文件,命名为Dockerfile
2、Dockerfile 文件编写指令及语法
1)指令
FROM
MAINTAINER
RUN
CMD
EXPOSE
ENV
ADD
COPY
ENTRYPOINT
VOLUME
USER
WORKDIR
ONBUILD
2)语法
引用了docker中文文档:http://www.docker.org.cn/dockerppt/114.html
1、FROM <image>
例子:FROM centos
FROM指定构建镜像的基础源镜像,如果本地没有指定的镜像,则会自动从Docker的公共库pull镜像下来。
FROM必须是Dockerfile中非注释行的第一个指令,即一个Dockerfile从FROM语句开始
FROM可以在一个DOCKERfile中出现多次,如果有需求在一个Dockerfile中创建多个镜像
2、MAINTAINER <name>
例子:MAINTAINER zxg zhutoyearn@163.com
指定创建镜像的用户
3、RUN <"executable","parm1","param2">
两种使用方式:
- RUN
- RUN "executable", "param1", "param2"
例子:RUN yum install wget -y
每条RUN指令将在当前镜像基础上执行指定命令,并提交为新的镜像,后续的RUN都在之前RUN提交后的镜像为基础,镜像是分层的,可以通过一个镜像的任何一个历史提交点来创建,类似源码的 版本控制 。
exec 方式会被解析为一个 JSON 数组,所以必须使用双引号而不是单引号。exec 方式不会调用一个命令 shell,所以也就不会继承相应的变量,如:
RUN [ "echo", "$HOME" ] #错误,这个个方法不会输出HOME变量,下面为正确方式
RUN [ "sh", "-c", "echo", "$HOME" ]
RUN 产生的缓存在下一次构建的适合是不会失效的,会被重用,可以使用--no-cache选择,即docker build-no-cache,如此便不会缓存
4、CMD <"executable",>
三种使用方式:
- CMD "executable","param1","param2"
- CMD "param1","param2"
- CMD command param1 param2 (shell form)
例子:CMD["nginx"]
CMD指定在 Dockerfile 中只能使用一次,如果有多个,则只有最后一个会生效。
CMD的目的是为了在启动容器时提供一个默认的命令执行选项。如果用户启动容器时指定了运行的命令,则会覆盖掉CMD指定的命令。
CMD会在启动容器的时候执行,build 时不执行,而RUN只是在构建镜像的时候执行,后续镜像构建完成之后,启动容器就与RUN无关了,这个初学者容易弄混这个概念,这里简单注解一下。
、EXPOSE <port>[<port>...]
告诉docker服务端容器对外映射的本地端口,需要在docker run的使用使用-p或者-P选项生效 例子:EXPOSE 80
、ENV
ENV <key> <value>
ENV <key>=<value>。。。
指定一个环节变量,会被后续RUN指令使用,并在容器运行时保留 例子:ENV myname zxg
ENV myhome beijing
ENV myname="zxg" myhome=beijing
、ADD
ADD <src>...<dest>
ADD复制本地主机文件、目录或者远程文件URLS从并且添加到容器指定路径中
支持通过Go的正则模式匹配,具体规则可参见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
注意如下:
- 路径必须是绝对路径,如果 不存在,会自动创建对应目录
- 路径必须是 Dockerfile 所在路径的相对路径
- 如果是一个目录,只会复制目录下的内容,而目录本身则不会被复制
、COPY
COPY <src>...<dest>
COPY复制新文件或者目录并且添加到容器指定路径中,用法和ADD相同,唯一区别时不能指定远程文件URLS。
、ENTRYPOINT
ENTRYPOINT "executable","param1","param2"
ENTRYPOINT command param1 param2(shell form)
配置容器启动后执行的命令,并且不可被 docker run 提供的参数覆盖,而CMD是可以被覆盖的。如果需要覆盖,则可以使用docker run --entrypoint选项。
每个 Dockerfile 中只能有一个ENTRYPOINT,当指定多个时,只有最后一个生效。
Exec form ENTRYPOINT 例子
通过ENTRYPOINT使用 exec form 方式设置稳定的默认命令和选项,而使用CMD添加默认之外经常被改动的选项。
FROM ubuntu
ENTRYPOINT ["top", "-b"]
CMD ["-c"]
通过 Dockerfile 使用ENTRYPOINT展示前台运行 Apache 服务
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 例子
这种方式会在/bin/sh -c中执行,会忽略任何CMD或者docker run命令行选项,为了确保docker stop能够停止长时间运行ENTRYPOINT的容器,确保执行的时候使用exec选项。
FROM ubuntu
ENTRYPOINT exec top -b
如果在ENTRYPOINT忘记使用exec选项,则可以使用CMD补上:
FROM ubuntu
ENTRYPOINT top -b
CMD --ignored-param1 # --ignored-param2 ... --ignored-param3 ... 依此类推
、VOLUME
VOLUME ["/data"]
创建一个可以从本地主机或其他容器挂载的挂载点,后续具体介绍
、USER
USER daemon
指定运行容器时的用户名或UID,后续RUN、CMD、ENTERPOINT也会使用指定用户 、WORKDIR
WORKDIR /path/to/workdir
为后续的RUN、CMD、ENTRYPOINT指令配置工作目录。可以使用多个WORKDIR指令,后续命令如果参数是相对路径,则会基于之前命令指定的路径
WORKDIR /a
WORKDIR b
WORKDIR c
RUN pwd
最终路径是/a/b/c
WORKDIR指令可以在ENV设置变量之后调用环境变量:
ENV DIRPATH /path
WORKDIR $DIRPATH/$DIRNAME
最终路径则为 /path/$DIRNAME
13、ONBUILD
ONBUILD [INSTRUCTION]
配置当所创建的镜像作为其他新创建镜像的基础镜像时,所执行的操作指令
例如:Dockerfile 使用如下的内容创建了镜像image-A:
[...]
ONBUILD ADD . /app/src
ONBUILD RUN /usr/local/bin/python-build --dri /app/src
[...]
3、例子examples,做一个centos安装了nginx及wget的镜像
[root@web1 docker]# vim Dockerfile
#this is docker file for centos-nginx
FROM centos
MAINTAINER zxg <victor@docker.com>
RUN yum install wget -y
RUN 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.html
RUN echo "daemon off;">>/etc/nginx/nginx.conf
EXPOSE
CMD ["nginx"]
4、使用build命令制作镜像
1)build命令说明
$ docker build --help
Usage: 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 # 移除过渡容器,即使构建失败
--no-cache=false Do not use cache when building the image # 不实用 cache
-q, --quiet=false Suppress the verbose output generated by the containers
--rm=true Remove intermediate containers after a successful build # 构建成功后移除过渡层容器
-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 .
整个过程还挺长,所以折叠了,可以点开看一下
[root@web1 docker]# docker build -t zxg/nginx1 .
Sending build context to Docker daemon 3.072 kB
Step / : FROM centos
---> 9f38484d220f
Step / : MAINTAINER zxg <victor@docker.com>
---> Using cache
---> 35983aa687ed
Step / : RUN yum install wget -y
---> Using cache
---> efb8205fc8d2
Step / : RUN rpm -ivh https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
---> Running in 56c5812e494f warning: /var/tmp/rpm-tmp.pS5KO3: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
Retrieving https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
Preparing... ########################################
Updating / installing...
epel-release-- ########################################
---> cf40357c60bb
Removing intermediate container 56c5812e494f
Step / : RUN yum install nginx -y
---> Running in 36ebe7b47657 Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
* base: mirrors.tuna.tsinghua.edu.cn
* epel: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.huaweicloud.com
https://hkg.mirror.rackspace.com/epel/7/x86_64/repodata/192b605ef6d0f773ad6162832c60509e1bc0817e28662ea77340078287b3b4d8-updateinfo.xml.bz2: [Errno 14] HTTPS Error 404 - Not Found
Trying other mirror.
To address this issue please refer to the below wiki article https://wiki.centos.org/yum-errors If 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 Found
Trying other mirror.
http://fedora.cs.nctu.edu.tw/epel/7/x86_64/repodata/dc10637460e531277a1cd82574de2dde2637fd3a9e90cd0282e9436d3a95b91d-primary.sqlite.bz2: [Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
Resolving Dependencies
--> Running transaction check
---> Package nginx.x86_64 :1.12.-.el7 will be installed
--> Processing Dependency: nginx-all-modules = :1.12.-.el7 for package: :nginx-1.12.-.el7.x86_64
--> Processing Dependency: nginx-filesystem = :1.12.-.el7 for package: :nginx-1.12.-.el7.x86_64
--> Processing Dependency: nginx-filesystem for package: :nginx-1.12.-.el7.x86_64
--> Processing Dependency: openssl for package: :nginx-1.12.-.el7.x86_64
--> Processing Dependency: libprofiler.so.()(64bit) for package: :nginx-1.12.-.el7.x86_64
--> Running transaction check
---> Package gperftools-libs.x86_64 :2.6.-.el7 will be installed
---> Package nginx-all-modules.noarch :1.12.-.el7 will be installed
--> Processing Dependency: nginx-mod-http-geoip = :1.12.-.el7 for package: :nginx-all-modules-1.12.-.el7.noarch
--> Processing Dependency: nginx-mod-http-image-filter = :1.12.-.el7 for package: :nginx-all-modules-1.12.-.el7.noarch
--> Processing Dependency: nginx-mod-http-perl = :1.12.-.el7 for package: :nginx-all-modules-1.12.-.el7.noarch
--> Processing Dependency: nginx-mod-http-xslt-filter = :1.12.-.el7 for package: :nginx-all-modules-1.12.-.el7.noarch
--> Processing Dependency: nginx-mod-mail = :1.12.-.el7 for package: :nginx-all-modules-1.12.-.el7.noarch
--> Processing Dependency: nginx-mod-stream = :1.12.-.el7 for package: :nginx-all-modules-1.12.-.el7.noarch
---> Package nginx-filesystem.noarch :1.12.-.el7 will be installed
---> Package openssl.x86_64 :1.0.2k-.el7_6. will be installed
--> Processing Dependency: openssl-libs(x86-) = :1.0.2k-.el7_6. for package: :openssl-1.0.2k-.el7_6..x86_64
--> Processing Dependency: make for package: :openssl-1.0.2k-.el7_6..x86_64
--> Running transaction check
---> Package make.x86_64 :3.82-.el7 will be installed
---> Package nginx-mod-http-geoip.x86_64 :1.12.-.el7 will be installed
--> Processing Dependency: GeoIP for package: :nginx-mod-http-geoip-1.12.-.el7.x86_64
--> Processing Dependency: libGeoIP.so.()(64bit) for package: :nginx-mod-http-geoip-1.12.-.el7.x86_64
---> Package nginx-mod-http-image-filter.x86_64 :1.12.-.el7 will be installed
--> Processing Dependency: gd for package: :nginx-mod-http-image-filter-1.12.-.el7.x86_64
--> Processing Dependency: libgd.so.()(64bit) for package: :nginx-mod-http-image-filter-1.12.-.el7.x86_64
---> Package nginx-mod-http-perl.x86_64 :1.12.-.el7 will be installed
--> Processing Dependency: perl >= 5.006001 for package: :nginx-mod-http-perl-1.12.-.el7.x86_64
--> Processing Dependency: perl(:MODULE_COMPAT_5.16.3) for package: :nginx-mod-http-perl-1.12.-.el7.x86_64
--> Processing Dependency: perl(Exporter) for package: :nginx-mod-http-perl-1.12.-.el7.x86_64
--> Processing Dependency: perl(XSLoader) for package: :nginx-mod-http-perl-1.12.-.el7.x86_64
--> Processing Dependency: perl(constant) for package: :nginx-mod-http-perl-1.12.-.el7.x86_64
--> Processing Dependency: perl(strict) for package: :nginx-mod-http-perl-1.12.-.el7.x86_64
--> Processing Dependency: perl(warnings) for package: :nginx-mod-http-perl-1.12.-.el7.x86_64
--> Processing Dependency: libperl.so()(64bit) for package: :nginx-mod-http-perl-1.12.-.el7.x86_64
---> Package nginx-mod-http-xslt-filter.x86_64 :1.12.-.el7 will be installed
--> Processing Dependency: libxslt.so.(LIBXML2_1.0.11)(64bit) for package: :nginx-mod-http-xslt-filter-1.12.-.el7.x86_64
--> Processing Dependency: libxslt.so.(LIBXML2_1.0.18)(64bit) for package: :nginx-mod-http-xslt-filter-1.12.-.el7.x86_64
--> Processing Dependency: libexslt.so.()(64bit) for package: :nginx-mod-http-xslt-filter-1.12.-.el7.x86_64
--> Processing Dependency: libxslt.so.()(64bit) for package: :nginx-mod-http-xslt-filter-1.12.-.el7.x86_64
---> Package nginx-mod-mail.x86_64 :1.12.-.el7 will be installed
---> Package nginx-mod-stream.x86_64 :1.12.-.el7 will be installed
---> Package openssl-libs.x86_64 :1.0.2k-.el7 will be updated
---> Package openssl-libs.x86_64 :1.0.2k-.el7_6. will be an update
--> Running transaction check
---> Package GeoIP.x86_64 :1.5.-.el7 will be installed
---> Package gd.x86_64 :2.0.-.el7 will be installed
--> Processing Dependency: libpng15.so.(PNG15_0)(64bit) for package: gd-2.0.-.el7.x86_64
--> Processing Dependency: libjpeg.so.(LIBJPEG_6.)(64bit) for package: gd-2.0.-.el7.x86_64
--> Processing Dependency: libpng15.so.()(64bit) for package: gd-2.0.-.el7.x86_64
--> Processing Dependency: libjpeg.so.()(64bit) for package: gd-2.0.-.el7.x86_64
--> Processing Dependency: libfreetype.so.()(64bit) for package: gd-2.0.-.el7.x86_64
--> Processing Dependency: libfontconfig.so.()(64bit) for package: gd-2.0.-.el7.x86_64
--> Processing Dependency: libXpm.so.()(64bit) for package: gd-2.0.-.el7.x86_64
--> Processing Dependency: libX11.so.()(64bit) for package: gd-2.0.-.el7.x86_64
---> Package libxslt.x86_64 :1.1.-.el7 will be installed
---> Package perl.x86_64 :5.16.-.el7_6 will be installed
--> Processing Dependency: perl(Socket) >= 1.3 for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(Scalar::Util) >= 1.10 for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl-macros for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(threads::shared) for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(threads) for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(Time::Local) for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(Time::HiRes) for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(Storable) for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(Socket) for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(Scalar::Util) for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(Pod::Simple::XHTML) for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(Pod::Simple::Search) for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(Getopt::Long) for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(Filter::Util::Call) for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(File::Temp) for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(File::Spec::Unix) for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(File::Spec::Functions) for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(File::Spec) for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(File::Path) for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(Cwd) for package: :perl-5.16.-.el7_6.x86_64
--> Processing Dependency: perl(Carp) for package: :perl-5.16.-.el7_6.x86_64
---> Package perl-Exporter.noarch :5.68-.el7 will be installed
---> Package perl-constant.noarch :1.27-.el7 will be installed
---> Package perl-libs.x86_64 :5.16.-.el7_6 will be installed
--> Running transaction check
---> Package fontconfig.x86_64 :2.13.-4.3.el7 will be installed
--> Processing Dependency: fontpackages-filesystem for package: fontconfig-2.13.-4.3.el7.x86_64
--> Processing Dependency: dejavu-sans-fonts for package: fontconfig-2.13.-4.3.el7.x86_64
---> Package freetype.x86_64 :2.8-.el7_6. will be installed
---> Package libX11.x86_64 :1.6.-.el7 will be installed
--> Processing Dependency: libX11-common >= 1.6.-.el7 for package: libX11-1.6.-.el7.x86_64
--> Processing Dependency: libxcb.so.()(64bit) for package: libX11-1.6.-.el7.x86_64
---> Package libXpm.x86_64 :3.5.-.el7 will be installed
---> Package libjpeg-turbo.x86_64 :1.2.-.el7 will be installed
---> Package libpng.x86_64 :1.5.-.el7_2 will be installed
---> Package perl-Carp.noarch :1.26-.el7 will be installed
---> Package perl-File-Path.noarch :2.09-.el7 will be installed
---> Package perl-File-Temp.noarch :0.23.-.el7 will be installed
---> Package perl-Filter.x86_64 :1.49-.el7 will be installed
---> Package perl-Getopt-Long.noarch :2.40-.el7 will be installed
--> Processing Dependency: perl(Pod::Usage) >= 1.14 for package: perl-Getopt-Long-2.40-.el7.noarch
--> Processing Dependency: perl(Text::ParseWords) for package: perl-Getopt-Long-2.40-.el7.noarch
---> Package perl-PathTools.x86_64 :3.40-.el7 will be installed
---> Package perl-Pod-Simple.noarch :3.28-.el7 will be installed
--> Processing Dependency: perl(Pod::Escapes) >= 1.04 for package: :perl-Pod-Simple-3.28-.el7.noarch
--> Processing Dependency: perl(Encode) for package: :perl-Pod-Simple-3.28-.el7.noarch
---> Package perl-Scalar-List-Utils.x86_64 :1.27-.el7 will be installed
---> Package perl-Socket.x86_64 :2.010-.el7 will be installed
---> Package perl-Storable.x86_64 :2.45-.el7 will be installed
---> Package perl-Time-HiRes.x86_64 :1.9725-.el7 will be installed
---> Package perl-Time-Local.noarch :1.2300-.el7 will be installed
---> Package perl-macros.x86_64 :5.16.-.el7_6 will be installed
---> Package perl-threads.x86_64 :1.87-.el7 will be installed
---> Package perl-threads-shared.x86_64 :1.43-.el7 will be installed
--> Running transaction check
---> Package dejavu-sans-fonts.noarch :2.33-.el7 will be installed
--> Processing Dependency: dejavu-fonts-common = 2.33-.el7 for package: dejavu-sans-fonts-2.33-.el7.noarch
---> Package fontpackages-filesystem.noarch :1.44-.el7 will be installed
---> Package libX11-common.noarch :1.6.-.el7 will be installed
---> Package libxcb.x86_64 :1.13-.el7 will be installed
--> Processing Dependency: libXau.so.()(64bit) for package: libxcb-1.13-.el7.x86_64
---> Package perl-Encode.x86_64 :2.51-.el7 will be installed
---> Package perl-Pod-Escapes.noarch :1.04-.el7_6 will be installed
---> Package perl-Pod-Usage.noarch :1.63-.el7 will be installed
--> Processing Dependency: perl(Pod::Text) >= 3.15 for package: perl-Pod-Usage-1.63-.el7.noarch
--> Processing Dependency: perl-Pod-Perldoc for package: perl-Pod-Usage-1.63-.el7.noarch
---> Package perl-Text-ParseWords.noarch :3.29-.el7 will be installed
--> Running transaction check
---> Package dejavu-fonts-common.noarch :2.33-.el7 will be installed
---> Package libXau.x86_64 :1.0.-2.1.el7 will be installed
---> Package perl-Pod-Perldoc.noarch :3.20-.el7 will be installed
--> Processing Dependency: perl(parent) for package: perl-Pod-Perldoc-3.20-.el7.noarch
--> Processing Dependency: perl(HTTP::Tiny) for package: perl-Pod-Perldoc-3.20-.el7.noarch
--> Processing Dependency: groff-base for package: perl-Pod-Perldoc-3.20-.el7.noarch
---> Package perl-podlators.noarch :2.5.-.el7 will be installed
--> Running transaction check
---> Package groff-base.x86_64 :1.22.-.el7 will be installed
---> Package perl-HTTP-Tiny.noarch :0.033-.el7 will be installed
---> Package perl-parent.noarch :0.225-.el7 will be installed
--> Finished Dependency Resolution Dependencies Resolved ================================================================================
Package Arch Version Repository
Size
================================================================================
Installing:
nginx x86_64 :1.12.-.el7 epel k
Installing for dependencies:
GeoIP x86_64 1.5.-.el7 base 1.5 M
dejavu-fonts-common noarch 2.33-.el7 base k
dejavu-sans-fonts noarch 2.33-.el7 base 1.4 M
fontconfig x86_64 2.13.-4.3.el7 base k
fontpackages-filesystem noarch 1.44-.el7 base 9.9 k
freetype x86_64 2.8-.el7_6. updates k
gd x86_64 2.0.-.el7 base k
gperftools-libs x86_64 2.6.-.el7 base k
groff-base x86_64 1.22.-.el7 base k
libX11 x86_64 1.6.-.el7 base k
libX11-common noarch 1.6.-.el7 base k
libXau x86_64 1.0.-2.1.el7 base k
libXpm x86_64 3.5.-.el7 base k
libjpeg-turbo x86_64 1.2.-.el7 base k
libpng x86_64 :1.5.-.el7_2 base k
libxcb x86_64 1.13-.el7 base k
libxslt x86_64 1.1.-.el7 base k
make x86_64 :3.82-.el7 base k
nginx-all-modules noarch :1.12.-.el7 epel k
nginx-filesystem noarch :1.12.-.el7 epel k
nginx-mod-http-geoip x86_64 :1.12.-.el7 epel k
nginx-mod-http-image-filter x86_64 :1.12.-.el7 epel k
nginx-mod-http-perl x86_64 :1.12.-.el7 epel k
nginx-mod-http-xslt-filter x86_64 :1.12.-.el7 epel k
nginx-mod-mail x86_64 :1.12.-.el7 epel k
nginx-mod-stream x86_64 :1.12.-.el7 epel k
openssl x86_64 :1.0.2k-.el7_6. updates k
perl x86_64 :5.16.-.el7_6 updates 8.0 M
perl-Carp noarch 1.26-.el7 base k
perl-Encode x86_64 2.51-.el7 base 1.5 M
perl-Exporter noarch 5.68-.el7 base k
perl-File-Path noarch 2.09-.el7 base k
perl-File-Temp noarch 0.23.-.el7 base k
perl-Filter x86_64 1.49-.el7 base k
perl-Getopt-Long noarch 2.40-.el7 base k
perl-HTTP-Tiny noarch 0.033-.el7 base k
perl-PathTools x86_64 3.40-.el7 base k
perl-Pod-Escapes noarch :1.04-.el7_6 updates k
perl-Pod-Perldoc noarch 3.20-.el7 base k
perl-Pod-Simple noarch :3.28-.el7 base k
perl-Pod-Usage noarch 1.63-.el7 base k
perl-Scalar-List-Utils x86_64 1.27-.el7 base k
perl-Socket x86_64 2.010-.el7 base k
perl-Storable x86_64 2.45-.el7 base k
perl-Text-ParseWords noarch 3.29-.el7 base k
perl-Time-HiRes x86_64 :1.9725-.el7 base k
perl-Time-Local noarch 1.2300-.el7 base k
perl-constant noarch 1.27-.el7 base k
perl-libs x86_64 :5.16.-.el7_6 updates k
perl-macros x86_64 :5.16.-.el7_6 updates k
perl-parent noarch :0.225-.el7 base k
perl-podlators noarch 2.5.-.el7 base k
perl-threads x86_64 1.87-.el7 base k
perl-threads-shared x86_64 1.43-.el7 base k
Updating for dependencies:
openssl-libs x86_64 :1.0.2k-.el7_6. updates 1.2 M Transaction Summary
================================================================================
Install Package (+ Dependent packages)
Upgrade ( Dependent package) Total download size: M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
warning: /var/cache/yum/x86_64//epel/packages/nginx-1.12.-.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
Public key for nginx-1.12.-.el7.x86_64.rpm is not installed
--------------------------------------------------------------------------------
Total kB/s | MB :
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
Importing GPG key 0x352C64E5:
Userid : "Fedora EPEL (7) <epel@fedoraproject.org>"
Fingerprint: 91e9 7d7c 4a5e 96f1 7f3e 888f 6a2f aea2 352c 64e5
Package : epel-release--.noarch (installed)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
Updating : :openssl-libs-1.0.2k-.el7_6..x86_64 /
Installing : fontpackages-filesystem-1.44-.el7.noarch /
Installing : :libpng-1.5.-.el7_2.x86_64 /
Installing : freetype-2.8-.el7_6..x86_64 /
Installing : dejavu-fonts-common-2.33-.el7.noarch /
Installing : dejavu-sans-fonts-2.33-.el7.noarch /
Installing : fontconfig-2.13.-4.3.el7.x86_64 /
Installing : :nginx-filesystem-1.12.-.el7.noarch /
Installing : libX11-common-1.6.-.el7.noarch /
Installing : gperftools-libs-2.6.-.el7.x86_64 /
Installing : libXau-1.0.-2.1.el7.x86_64 /
Installing : libxcb-1.13-.el7.x86_64 /
Installing : libX11-1.6.-.el7.x86_64 /
Installing : libXpm-3.5.-.el7.x86_64 /
Installing : libxslt-1.1.-.el7.x86_64 /
Installing : groff-base-1.22.-.el7.x86_64 /
Installing : :perl-parent-0.225-.el7.noarch /
Installing : perl-HTTP-Tiny-0.033-.el7.noarch /
Installing : perl-podlators-2.5.-.el7.noarch /
Installing : perl-Pod-Perldoc-3.20-.el7.noarch /
Installing : :perl-Pod-Escapes-1.04-.el7_6.noarch /
Installing : perl-Text-ParseWords-3.29-.el7.noarch /
Installing : perl-Encode-2.51-.el7.x86_64 /
Installing : perl-Pod-Usage-1.63-.el7.noarch /
Installing : :perl-libs-5.16.-.el7_6.x86_64 /
Installing : :perl-macros-5.16.-.el7_6.x86_64 /
Installing : :perl-Time-HiRes-1.9725-.el7.x86_64 /
Installing : perl-Exporter-5.68-.el7.noarch /
Installing : perl-constant-1.27-.el7.noarch /
Installing : perl-Time-Local-1.2300-.el7.noarch /
Installing : perl-Carp-1.26-.el7.noarch /
Installing : perl-Storable-2.45-.el7.x86_64 /
Installing : perl-PathTools-3.40-.el7.x86_64 /
Installing : perl-Scalar-List-Utils-1.27-.el7.x86_64 /
Installing : perl-File-Temp-0.23.-.el7.noarch /
Installing : perl-File-Path-2.09-.el7.noarch /
Installing : perl-threads-shared-1.43-.el7.x86_64 /
Installing : perl-threads-1.87-.el7.x86_64 /
Installing : perl-Filter-1.49-.el7.x86_64 /
Installing : perl-Socket-2.010-.el7.x86_64 /
Installing : :perl-Pod-Simple-3.28-.el7.noarch /
Installing : perl-Getopt-Long-2.40-.el7.noarch /
Installing : :perl-5.16.-.el7_6.x86_64 /
Installing : GeoIP-1.5.-.el7.x86_64 /
Installing : libjpeg-turbo-1.2.-.el7.x86_64 /
Installing : gd-2.0.-.el7.x86_64 /
Installing : :make-3.82-.el7.x86_64 /
Installing : :openssl-1.0.2k-.el7_6..x86_64 /
Installing : :nginx-mod-http-image-filter-1.12.-.el7.x86_64 /
Installing : :nginx-mod-mail-1.12.-.el7.x86_64 /
Installing : :nginx-mod-stream-1.12.-.el7.x86_64 /
Installing : :nginx-mod-http-xslt-filter-1.12.-.el7.x86_64 /
Installing : :nginx-mod-http-perl-1.12.-.el7.x86_64 /
Installing : :nginx-mod-http-geoip-1.12.-.el7.x86_64 /
Installing : :nginx-all-modules-1.12.-.el7.noarch /
Installing : :nginx-1.12.-.el7.x86_64 /
Cleanup : :openssl-libs-1.0.2k-.el7.x86_64 /
Verifying : :nginx-all-modules-1.12.-.el7.noarch /
Verifying : fontconfig-2.13.-4.3.el7.x86_64 /
Verifying : perl-HTTP-Tiny-0.033-.el7.noarch /
Verifying : :nginx-mod-http-image-filter-1.12.-.el7.x86_64 /
Verifying : perl-threads-shared-1.43-.el7.x86_64 /
Verifying : :perl-Time-HiRes-1.9725-.el7.x86_64 /
Verifying : :perl-Pod-Escapes-1.04-.el7_6.noarch /
Verifying : :make-3.82-.el7.x86_64 /
Verifying : perl-Exporter-5.68-.el7.noarch /
Verifying : perl-constant-1.27-.el7.noarch /
Verifying : perl-PathTools-3.40-.el7.x86_64 /
Verifying : :nginx-1.12.-.el7.x86_64 /
Verifying : :libpng-1.5.-.el7_2.x86_64 /
Verifying : :nginx-mod-mail-1.12.-.el7.x86_64 /
Verifying : :nginx-mod-stream-1.12.-.el7.x86_64 /
Verifying : dejavu-fonts-common-2.33-.el7.noarch /
Verifying : fontpackages-filesystem-1.44-.el7.noarch /
Verifying : libjpeg-turbo-1.2.-.el7.x86_64 /
Verifying : :perl-parent-0.225-.el7.noarch /
Verifying : :nginx-mod-http-xslt-filter-1.12.-.el7.x86_64 /
Verifying : GeoIP-1.5.-.el7.x86_64 /
Verifying : :perl-libs-5.16.-.el7_6.x86_64 /
Verifying : groff-base-1.22.-.el7.x86_64 /
Verifying : perl-File-Temp-0.23.-.el7.noarch /
Verifying : :perl-Pod-Simple-3.28-.el7.noarch /
Verifying : perl-Getopt-Long-2.40-.el7.noarch /
Verifying : perl-Time-Local-1.2300-.el7.noarch /
Verifying : libxcb-1.13-.el7.x86_64 /
Verifying : :perl-macros-5.16.-.el7_6.x86_64 /
Verifying : :perl-5.16.-.el7_6.x86_64 /
Verifying : libXpm-3.5.-.el7.x86_64 /
Verifying : :nginx-mod-http-perl-1.12.-.el7.x86_64 /
Verifying : :openssl-1.0.2k-.el7_6..x86_64 /
Verifying : perl-Carp-1.26-.el7.noarch /
Verifying : libxslt-1.1.-.el7.x86_64 /
Verifying : libX11-1.6.-.el7.x86_64 /
Verifying : perl-Storable-2.45-.el7.x86_64 /
Verifying : dejavu-sans-fonts-2.33-.el7.noarch /
Verifying : perl-Scalar-List-Utils-1.27-.el7.x86_64 /
Verifying : gd-2.0.-.el7.x86_64 /
Verifying : :nginx-mod-http-geoip-1.12.-.el7.x86_64 /
Verifying : perl-Pod-Usage-1.63-.el7.noarch /
Verifying : perl-Encode-2.51-.el7.x86_64 /
Verifying : perl-Pod-Perldoc-3.20-.el7.noarch /
Verifying : perl-podlators-2.5.-.el7.noarch /
Verifying : libXau-1.0.-2.1.el7.x86_64 /
Verifying : perl-File-Path-2.09-.el7.noarch /
Verifying : perl-threads-1.87-.el7.x86_64 /
Verifying : gperftools-libs-2.6.-.el7.x86_64 /
Verifying : libX11-common-1.6.-.el7.noarch /
Verifying : perl-Filter-1.49-.el7.x86_64 /
Verifying : freetype-2.8-.el7_6..x86_64 /
Verifying : perl-Text-ParseWords-3.29-.el7.noarch /
Verifying : perl-Socket-2.010-.el7.x86_64 /
Verifying : :nginx-filesystem-1.12.-.el7.noarch /
Verifying : :openssl-libs-1.0.2k-.el7_6..x86_64 /
Verifying : :openssl-libs-1.0.2k-.el7.x86_64 / Installed:
nginx.x86_64 :1.12.-.el7 Dependency Installed:
GeoIP.x86_64 :1.5.-.el7
dejavu-fonts-common.noarch :2.33-.el7
dejavu-sans-fonts.noarch :2.33-.el7
fontconfig.x86_64 :2.13.-4.3.el7
fontpackages-filesystem.noarch :1.44-.el7
freetype.x86_64 :2.8-.el7_6.
gd.x86_64 :2.0.-.el7
gperftools-libs.x86_64 :2.6.-.el7
groff-base.x86_64 :1.22.-.el7
libX11.x86_64 :1.6.-.el7
libX11-common.noarch :1.6.-.el7
libXau.x86_64 :1.0.-2.1.el7
libXpm.x86_64 :3.5.-.el7
libjpeg-turbo.x86_64 :1.2.-.el7
libpng.x86_64 :1.5.-.el7_2
libxcb.x86_64 :1.13-.el7
libxslt.x86_64 :1.1.-.el7
make.x86_64 :3.82-.el7
nginx-all-modules.noarch :1.12.-.el7
nginx-filesystem.noarch :1.12.-.el7
nginx-mod-http-geoip.x86_64 :1.12.-.el7
nginx-mod-http-image-filter.x86_64 :1.12.-.el7
nginx-mod-http-perl.x86_64 :1.12.-.el7
nginx-mod-http-xslt-filter.x86_64 :1.12.-.el7
nginx-mod-mail.x86_64 :1.12.-.el7
nginx-mod-stream.x86_64 :1.12.-.el7
openssl.x86_64 :1.0.2k-.el7_6.
perl.x86_64 :5.16.-.el7_6
perl-Carp.noarch :1.26-.el7
perl-Encode.x86_64 :2.51-.el7
perl-Exporter.noarch :5.68-.el7
perl-File-Path.noarch :2.09-.el7
perl-File-Temp.noarch :0.23.-.el7
perl-Filter.x86_64 :1.49-.el7
perl-Getopt-Long.noarch :2.40-.el7
perl-HTTP-Tiny.noarch :0.033-.el7
perl-PathTools.x86_64 :3.40-.el7
perl-Pod-Escapes.noarch :1.04-.el7_6
perl-Pod-Perldoc.noarch :3.20-.el7
perl-Pod-Simple.noarch :3.28-.el7
perl-Pod-Usage.noarch :1.63-.el7
perl-Scalar-List-Utils.x86_64 :1.27-.el7
perl-Socket.x86_64 :2.010-.el7
perl-Storable.x86_64 :2.45-.el7
perl-Text-ParseWords.noarch :3.29-.el7
perl-Time-HiRes.x86_64 :1.9725-.el7
perl-Time-Local.noarch :1.2300-.el7
perl-constant.noarch :1.27-.el7
perl-libs.x86_64 :5.16.-.el7_6
perl-macros.x86_64 :5.16.-.el7_6
perl-parent.noarch :0.225-.el7
perl-podlators.noarch :2.5.-.el7
perl-threads.x86_64 :1.87-.el7
perl-threads-shared.x86_64 :1.43-.el7 Dependency Updated:
openssl-libs.x86_64 :1.0.2k-.el7_6. Complete!
---> 996824f87698
Removing intermediate container 36ebe7b47657
Step / : ADD index.html /usr/share/nginx/html/index.html
---> a21387c003a7
Removing intermediate container 74dfd64941b1
Step / : RUN echo "daemon off;">>/etc/nginx/nginx.conf
---> Running in bd60f92d877e ---> 3b20cd6163a8
Removing intermediate container bd60f92d877e
Step / : EXPOSE
---> Running in 54e388a3fd21
---> 2aeecbaba79b
Removing intermediate container 54e388a3fd21
Step / : CMD nginx
---> Running in 32d4b23b050c
---> 3babdf3c6c6d
Removing intermediate container 32d4b23b050c
Successfully built 3babdf3c6c6d
点击查看整个过程
5、验证一下,并用curl测试
[root@web1 docker]# docker run -d --name my_nginx1 zxg/nginx1 #后台运行整个容器
751a8f9dda48c034d40b8855b3dd6c7aaf785eeaa9ae404c5eb3c0271e434f50
[root@web1 docker]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
751a8f9dda48 zxg/nginx1 "nginx" About a minute ago Up About a minute /tcp my_nginx1
[root@web1 docker]# docker exec -it my_nginx1 bash #进入容器
[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 /]# exit
exit
[root@web1 docker]#
[root@751a8f9dda48 html]# curl 127.0.0.1
this 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.2
this is docker-centos7-nginx1
[root@web1 ~]#
转载请注明出处:https://www.cnblogs.com/zhangxingeng/p/11394374.html
Docker3-Dockerfile创建镜像的方法(推荐docker file这种方法)的更多相关文章
- docker——Dockerfile创建镜像
写在前面: 继续docker的学习,昨天用docker成功跑了tomcat,但是在centos中镜像跑的容器手动装jdk和tomcat,今天学习用Dockerfile创建镜像,并在上面搭建java环境 ...
- docker常用命令、镜像命令、容器命令、数据卷,使用dockerFile创建镜像,dockefile的语法规则。
一.docker常用命令? 1. 常用帮助命令 1.1 docker的信息以及版本号 /* docker info 查看docker的信息 images2 docker本身就是一个镜像. docker ...
- Dockerfile创建镜像
Dockerfile是一个文本格式的配置文件,用户可以使用Dockerfile来快速创建自定义的镜像. Dockerfile由一行行命令语句组成,并且支持易#开头的注释行. 一般而言Dockerfil ...
- docker学习笔记6:利用dockerfile创建镜像介绍(生成简单web服务器镜像)
本文介绍如何利用dockerfile来创建镜像.下面介绍具体的操作过程: 一.创建构建环境 操作示例如下: xxx@ubuntu:~$ pwd /home/xxx xxx@ubuntu:~$ mkdi ...
- [转]Docker基础-使用Dockerfile创建镜像
本文转自:https://www.cnblogs.com/jie-fang/p/7927643.html 1.基本结构 Dockerfile由一行行命令语句组成,并支持以#开头的注释行.例如: # T ...
- Docker基础-使用Dockerfile创建镜像
1.基本结构 Dockerfile由一行行命令语句组成,并支持以#开头的注释行.例如: # This dockerfile uses the ubuntu image # VERSION 2 - ED ...
- Docker学习笔记之通过 Dockerfile 创建镜像
0x00 概述 由于 Docker 镜像的结构优势,使它的占用空间远小于普通的虚拟机镜像,而这就大幅减少了 Docker 镜像在网络或者其他介质中转移所花费的时间,进而提高了我们进行迁移部署的效率.不 ...
- docker Dockerfile 创建镜像
Docker 组件 1. docker client : docker的客户端 2. docker server : docker daemon的主要组成部分,接受用户通过docker client发 ...
- Docker实战(六)之使用Dockerfile创建镜像
Dockervile是一个文本格式的配置文件,用户可以使用Dockerfile来快速创建自定义镜像. 1.基本结构 Dockerfile由一行行命令语句组成,并且支持以#开头的注释行. 一般而言,Do ...
随机推荐
- react用脚手架创建一个react单页面项目,react起手式
官网地址:https://react.docschina.org/ 确保本地安装了Node.js node的版本大于8.10 npm的版本大于5.6 1.在本地的某个位置创建一个文件夹,执行以下 ...
- Jmeter(四十一)_图片爬虫
今天教大家用元件组合,做一个网页图片爬虫. 需要用到的元件:循环控制器+计数器+xpath提前器+函数嵌套+beanshell代码 首先我们确定一下要爬取的图片网站:https://dp.pconli ...
- deepin深度学习环境配置
deepin是一个精致优美的系统.最近因为工作需要在deepin上配置深度学习环境,话不多说,接下来记录下整个的配置过程. ×××本篇文章适合对深度学习环境配置有一定了解且对deepin系统感兴趣的同 ...
- Sparrow-WiFi:一款Linux平台下的图形化WiFi及蓝牙分析工具
工具概述 Sparrow-wifi本质上一款针对下一代2.4GHz和5GHz的WiFi频谱感知工具,它不仅提供了GUI图形化用户界面,而且功能更加全面,可以代替类似inSSIDer和linssid之类 ...
- Oracle系列四 单行函数查询语句
单行函数 操作数据对象 接受参数返回一个结果 只对一行进行变换 每行返回一个结果 可以转换数据类型 可以嵌套 参数可以是一列或一个值 包含:字符,数值,日期,转换,通用 字符函数 1.大小写控制函数: ...
- Jmeter多业务混合场景如何设置各业务所占并发比例
在进行多业务混合场景测试中,需要分配每个场景占比. 具体有两种方式: 1.多线程组方式: 2.逻辑控制器控制: 第一种: jmeter一个测试计划可以添加多个线程组,我们把不同的业务放在不同的线程组中 ...
- CFCA证书工具类
jar:com.cfca.pkibase-1.0.jar import java.io.UnsupportedEncodingException; import java.security.Secur ...
- 【Log】logback实现每个类和包自定义级别输出
本例想实现对类或者包中的日志,自定义级别输出 方法一 1.自定义日志级别方式如下: 代码文件:Logger monitorLogger = LoggerFactory.getLogger(" ...
- c# 并行循环支持 async
var bag = new ConcurrentBag<object>(); var tasks = myCollection.Select(async item => { // s ...
- django安装使用xadmin
Xadmin介绍 直接替换掉Django自带的admin系统,并提供了很多有用的东西:完全的可扩展的插件支持,基于Twitter Bootstrap的漂亮UI. 完全替代Django admin 支持 ...