30选5玩法|福彩30选5开奖结果321|

Docker 使用Dockerfile构建镜像

来源:本站原创 Docker 超过430 views围观 0条评论

编写Dockerfile

"/opt/dockerfiles/nginx/Dockerfile" 16L, 347C

——–开始

#this is docker file
#Version 1
#Author: Jeff
#Base image
FROM centos

#Maintainer
MAINTAINER jeff [email protected]

#Commands
RUN rpm -ivh https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
RUN yum install -y nginx
ADD index.html /usr/share/nginx/html/index.html
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
EXPOSE 80
CMD ["nginx"]

———-结速

[[email protected] nginx]# pwd
/opt/dockerfiles/nginx
[[email protected] nginx]# mv nginx_v3 Dockerfile
[[email protected] nginx]#
[[email protected] nginx]#
[[email protected] nginx]# ll
total 4
-rw-r–r–. 1 root root 347 Jan 13 02:59 Dockerfile
[[email protected] nginx]# vim Dockerfile
[[email protected] nginx]#
[[email protected] nginx]#
[[email protected] nginx]#
[[email protected] nginx]# docker build -t jeff/nginx_1:v3 .
Sending build context to Docker daemon 2.048 kB
Step 1 : FROM centos
—> ff426288ea90
Step 2 : MAINTAINER jeff [email protected]
—> Running in 1498cac44a24
—> 8676e2b6fd8f
Removing intermediate container 1498cac44a24
Step 3 : RUN rpm -ivh https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
—> Running in c0afc77f9850
warning: /var/tmp/rpm-tmp.MqtlDv: 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-7-11                     ########################################
—> 27aab1031bd5
Removing intermediate container c0afc77f9850
Step 4 : RUN yum install -y nginx
—> Running in 61da26df94fa
Loaded plugins: fastestmirror, ovl

 

 

———以下?#24039;?#25805;作—————

#this is docker file
#Version 1
#Author: Jeff
#Base image
FROM centos

#Maintainer
MAINTAINER jeff [email protected]

#Commands
RUN rpm -ivh https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
RUN yum install -y nginx
ADD index.html /usr/share/nginx/html/index.html
               /usr/share/nginx/html/
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
EXPOSE 80   ——证明是没毛用
CMD ["nginx"]

——–执行验证————
[[email protected] nginx]# docker build -t jeff/nginx_1:v3 .
Sending build context to Docker daemon 2.048 kB
Step 1 : FROM centos
—> ff426288ea90
Step 2 : MAINTAINER jeff [email protected]
—> Running in 1498cac44a24
—> 8676e2b6fd8f
Removing intermediate container 1498cac44a24
Step 3 : RUN rpm -ivh https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
—> Running in c0afc77f9850
warning: /var/tmp/rpm-tmp.MqtlDv: 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-7-11                     ########################################
—> 27aab1031bd5
Removing intermediate container c0afc77f9850
Step 4 : RUN yum install -y nginx
—> Running in 61da26df94fa
Loaded plugins: fastestmirror, ovl
http://ftp.jaist.ac.jp/pub/Linux/Fedora/epel/7/x86_64/repodata/673486a8042817cf7ce895d3d4e4f3fe25e12e41b63dce06f580d733673ea950-primary.sqlite.bz2: [Errno 12] Timeout on http://ftp.jaist.ac.jp/pub/Linux/Fedora/epel/7/x86_64/repodata/673486a8042817cf7ce895d3d4e4f3fe25e12e41b63dce06f580d733673ea950-primary.sqlite.bz2: (28, ‘Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds’)
Trying other mirror.

================================================================================
Package                         Arch       Version              Repository
                                                                           Size
================================================================================
Installing:
nginx                           x86_64     1:1.12.2-1.el7       epel     529 k

Transaction Summary
================================================================================
Install  1 Package (+54 Dependent packages)

Total download size: 18 M
Installed size: 55 M

  nginx.x86_64 1:1.12.2-1.el7                                                  
                              

Complete!
—> e4fac0822687
Removing intermediate container 61da26df94fa
Step 5 : ADD index.html /usr/share/nginx/html/index.html————-
lstat index.html: no such file or directory

妥妥的失败

原因如下
Step 6 : ADD jeff.html /usr/share/nginx/html/ ——–原文件不存在,需要指定路径即可解决———-
lstat jeff.html: no such file or directory
[[email protected] ~]# cd /opt/dockerfiles/nginx/
[[email protected] nginx]# echo "jeff" > jeff.html   ——增加文件
[[email protected] nginx]# ll
total 8
-rw-r–r–. 1 root root 337 Jan 13 04:03 Dockerfile
-rw-r–r–. 1 root root   5 Jan 13 04:05 jeff.html
[[email protected] nginx]# docker build -t jeff/nginx_1:v5 /opt/dockerfiles/nginx/
Sending build context to Docker daemon 3.072 kB
Step 1 : FROM centos
—> ff426288ea90
Step 2 : MAINTAINER jeff [email protected]
—> Using cache
—> 8676e2b6fd8f
Step 3 : RUN rpm -ivh https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
—> Using cache
—> 27aab1031bd5
Step 4 : RUN yum install -y nginx
—> Using cache
—> e4fac0822687
Step 5 : RUN echo "daemon off;" >> /etc/nginx/nginx.conf
—> Using cache
—> ae261671bde6
Step 6 : ADD jeff.html /usr/share/nginx/html/
—> a2c0d52161b2
Removing intermediate container e80f83b386f2
Step 7 : EXPOSE 880
—> Running in ce08659e82c6
—> d4ffb8d7752d
Removing intermediate container ce08659e82c6
Step 8 : CMD nginx
—> Running in d280154efa46
—> ad7465e37bd8
Removing intermediate container d280154efa46
Successfully built ad7465e37bd8        ——-成功
[[email protected] nginx]#

验证
[[email protected] ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
jeff/nginx_1        v5                  ad7465e37bd8        2 minutes ago       403.1 MB

启动构建的镜像
注意:需要对应EXPOSE里面的端口
[[email protected] ~]# docker run -d -p 88:80  jeff/nginx_1:v6  ——88:80是我后期改过的.按原文件是88:880
b9014e39c1b03a762089a68cc56f0e38cf141b151442e41433ad56e558ecda68

http验证
https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
—> Using cache
—> 27aab1031bd5
Step 4 : RUN yum install -y nginx
—> Using cache
—> e4fac0822687
Step 5 : RUN echo "daemon off;" >> /etc/nginx/nginx.conf
—> Using cache
—> ae261671bde6
Step 6 : ADD jeff.html /usr/share/nginx/html/
—> 217a4dc6b3a3
Removing intermediate container c4dc7388b839
Step 7 : EXPOSE 880   ————–注意这个端口
—> Running in 372336d45674
—> a6b10f5a95d5
Removing intermediate container 372336d45674
Step 8 : CMD nginx
—> Running in 9750e2726d6d
—> f4c2c76b4884
Removing intermediate container 9750e2726d6d
Successfully built f4c2c76b4884
[[email protected] ~]#

[[email protected] ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
jeff/nginx_1        v7—成功                  f4c2c76b4884        50 seconds ago      403.1 MB

启动构建的镜像
[[email protected] ~]# docker run -d -p 89:880  jeff/nginx_1:v7
412141f05616532b11506706aa1b1a0e955e185dd8bf7965e290caa0c1de8b5a
[[email protected] ~]#

验证端口
netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name   
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      906/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1007/master        
tcp6       0      0 :::82                   :::*                    LISTEN      21433/docker-proxy-
tcp6       0      0 :::22                   :::*                    LISTEN      906/sshd           
tcp6       0      0 :::88                   :::*                    LISTEN      26769/docker-proxy-
tcp6       0      0 :::89    —–正常        :::*                    LISTEN      27182/docker-proxy-
tcp6       0      0 ::1:25                  :::*                    LISTEN      1007/master        
[[email protected] ~]#

http://192.168.142.128:89/ 无法打开

所?#34892;?#35201;重新理解EXPOSE ?#24039;?#24847;思
——–注意——–
本质上说,EXPOSE或者–expose只是为其他命令提供所需信息的元数据,意思是没毛用。

重新进行测试

[[email protected] ~]# docker run -d -p 89:80  jeff/nginx_1:v7
2bc6b042cfbc31219f2716005f7db223dc01af98a630d86eb2b2b41634ebc375

[[email protected] ~]# curl
^C
[[email protected] ~]# curl

文章出自:CCIE那点事 http://www.rygqfb.tw/ 版权所?#23567;?#26412;站文章除注明出处外,皆为作者原创文章,可自由引用,但请注明来源。 禁止全文转载。
本文链接:http://www.rygqfb.tw/?p=3682转载请注明转自CCIE那点事
如果?#19981;叮?a title="CCIE那点事 | IT运维故障发现和解决基地 我致力于为企业IT管理提供助力!" href="http://www.rygqfb.tw/?feed=rss2" target="_blank">点此订阅本站
  • 相关文章
  • 为您推荐
  • 各种观点
?
暂时还木有人评论,坐等沙发!
发表评论

您必须 [ 登录 ] 才能发表留言!

?
?
30选5玩法
秒速时时彩是真的吗 极速快乐十分开奖 闲来麻将 甘肃快三形态走势一定 中奖一千万多久到账 秒速飞艇是合法的吗 申穆出资 四川麻将技巧 河北省快三综合走势图 股票指数计算例题