编写Dockerfile来构建nginx:latest镜像

1.新建 Dockerfile 文件

1.在 Dockerfile 目录下,新建一个名为 Dockerfile 文件:

[root@VM_0_6_centos src]# pwd
/usr/local/src
[root@VM_0_6_centos src]# mdkir Dockerfile 
[root@VM_0_6_centos src]# ls
Dockerfile 
[root@VM_0_6_centos src]# cd Dockerfile/

[root@VM_0_6_centos Dockerfile]# touch Dockerfile

[root@VM_0_6_centos Dockerfile]# pwd
/usr/local/src/Dockerfile
[root@VM_0_6_centos Dockerfile]# ls
Dockerfile
[root@VM_0_6_centos Dockerfile]# vi Dockerfile 

2.在Dockerfile 文件内添加以下内容:

From nginx18:v1
CMD /usr/local/webserver/nginx/sbin/nginx

FROM:定制的镜像都是基于 FROM 的本地镜像,这里的 nginx 就是定制需要的基础镜像。后续的操作都是基于 nginx。
RUN:用于执行后面跟着的命令行命令。RUN 是在 docker build 时运行。
CMD: 类似于 RUN 指令,用于运行程序,但二者运行的时间点不同。CMD 在docker run 时运行。

2.开始构建nginx:latest镜像

docker build -t nginx:latest .

以下示例,通过目录下的 Dockerfile 构建一个 nginx:latest(镜像名称:镜像标签)。
注:最后的 . 代表本次执行的上下文路径。

[root@VM_0_6_centos Dockerfile]# ls
Dockerfile
[root@VM_0_6_centos Dockerfile]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx18             v1                  828b659f7a77        2 days ago          487MB
centos              latest              0d120b6ccaa8        13 days ago         215MB
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值