Docker 镜像与制作(三)DockerFile 制作yum版 nginx 镜像

DockerFile 制作yum版 nginx 镜像:

  1. 准备目录
mkdir -pv /opt/dockerfile/web/nginx
  1. 编写dockerfile文件
vim /opt/dockerfile/web/nginx/Dockerfile
#Nginx web image

FROM centos:latest

RUN yum install epel-release -y
RUN yum install nginx -y && rm -rf /usr/share/nginx/html/*
ADD html.tar.gz /usr/share/nginx/html/
#copy 

EXPOSE 80 443 8080

CMD ["/usr/sbin/nginx","-g","daemon off;"]

RUN就是运行shell命令
ADD

  1. 创建网页测试文件
vi /opt/dockerfile/web/nginx/index.html
<h1> docker nginx test, nginx container by dockerfile</h1>
  1. 打包网页测试文件
tar czvf html.tar.gz index.html 
  1. 构建镜像
docker build -t chenjb/centos-nginx /opt/dockerfile/web/nginx/

[外链图片转存失败(img-cnxsBmYN-1568380277357)(png/2019-09-12-15-34-22.png)]

  1. 查看镜像
docker images
  1. 启动容器
docker run -it -d -p 80:80 --name "nginx-test" chenjb/centos-nginx 

[外链图片转存失败(img-YYRhI3i7-1568380277358)(png/2019-09-12-15-39-05.png)]

  1. 查看进程
docker ps
  1. 测试网页
# curl localhost
<h1> docker ginx test, nginx container by dockerfile</h1>
发布了254 篇原创文章 · 获赞 346 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/weixin_42758707/article/details/100811092