19-docker 容器Dockerfile文件
1.建立镜像文件夹,Dockerfile一定要这个名字,首位字母大写
[root@docker03 ~]# mkdir /opt/nginx [root@docker03 ~]# cd /opt/nginx/ [root@docker03 nginx]# vim Dockerfile
2.编辑Dockerfile文件
[root@docker03 nginx]# vim Dockerfile
# This is dockerfile or nignx
# VERSION 1
# Author:Hyman
# 基础镜像,镜像文件是centos
FROM centos
# 维护者信息
MAINTAINER sunmmi@qq.com
# 相关操作
RUN rpm -ivh https://mirrors.aliyun.com/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm
&& yum install nginx -y
&& echo 'Hello, Docker Page! ' > /usr/share/nginx/html/index.html
# 增加文件
#ADD index.html /usr/share/nginx/html/index.html
# 配置nginx参数
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
# 设置开放端口
EXPOSE 80
# 执行命令
CMD ["nginx"]
3.运行Dockerfile文件,根据dockerfile生成nginx镜像,-t就是tag标签的意思
[root@docker03 nginx]# docker build -t nginx:v3 /opt/nginx/ Sending build context to Docker daemon 2.56kB Step 1/6 : FROM centos ---> 2d194b392dd1 Step 2/6 : MAINTAINER sunmmi@qq.com ---> Running in addedc6254a7 Removing intermediate container addedc6254a7 ---> a8adc908bf98 Step 3/6 : RUN rpm -ivh https://mirrors.aliyun.com/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm && yum install nginx -y && echo '<h1>Hello, Docker Page! </h1>' > /usr/share/nginx/html/index.html ---> Running in a38c15b3cbfe warning: /var/tmp/rpm-tmp.GjOUaX: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY Retrieving https://mirrors.aliyun.com/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm Preparing... ######################################## Updating / installing... epel-release-7-11 ######################################## Loaded plugins: fastestmirror, ovl Determining fastest mirrors * base: mirrors.aliyun.com * epel: mirrors.tongji.edu.cn * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com Resolving Dependencies --> Running transaction check ---> Package nginx.x86_64 1:1.12.2-1.el7 will be installed --> Processing Dependency: nginx-all-modules = 1:1.12.2-1.el7 for package: 1:nginx-1.12.2-1.el7.x86_64 --> Processing Dependency: nginx-filesystem = 1:1.12.2-1.el7 for package: 1:nginx-1.12.2-1.el7.x86_64 --> Processing Dependency: nginx-filesystem for package: 1:nginx-1.12.2-1.el7.x86_64 --> Processing Dependency: openssl for package: 1:nginx-1.12.2-1.el7.x86_64 --> Processing Dependency: libprofiler.so.0()(64bit) for package: 1:nginx-1.12.2-1.el7.x86_64 --> Running transaction check ....... ....... perl-threads-shared.x86_64 0:1.43-6.el7 Complete! Removing intermediate container a38c15b3cbfe ---> c3ed6d22f75d Step 4/6 : RUN echo "daemon off;" >> /etc/nginx/nginx.conf ---> Running in 4da76b9e7e9b Removing intermediate container 4da76b9e7e9b ---> f63645ce4b69 Step 5/6 : EXPOSE 80 ---> Running in 94e32cb0a7a3 Removing intermediate container 94e32cb0a7a3 ---> 5b28bd15dcef Step 6/6 : CMD ["nginx"] ---> Running in 6e83ea5c6feb Removing intermediate container 6e83ea5c6feb ---> 4f3032128c0e Successfully built 4f3032128c0e Successfully tagged nginx:v3 [root@docker03 nginx]#
4.启动新的镜像
[root@docker03 nginx]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx v3 4f3032128c0e 2 minutes ago 384MB nginx v2 3372b9a7514a About an hour ago 109MB nginx latest 7f70b30f2cc6 22 hours ago 109MB node latest 4885ab8871c2 24 hours ago 673MB sunmmi/nginx latest 1fd61459671b 2 days ago 385MB centos latest 2d194b392dd1 2 weeks ago 195MB registry latest d1fd7d86a825 2 months ago 33.3MB alpine latest 3fd9065eaf02 2 months ago 4.14MB hello-world latest f2a91732366c 4 months ago 1.85kB # 启动刚才build的镜像,可以看到hello Docker Page文件 [root@docker03 nginx]# docker run -itd --name nginx03 -p 8080:80 nginx:v3 30d92fab23dae3db65ea034d093e2a3a38e872561f87257966b3fbb9137737a7 [root@docker03 nginx]# curl 192.168.1.26:8080 Hello, Docker Page! [root@docker03 nginx]#

浙公网安备 33010602011771号