DockerFile 制作yum版 nginx 镜像:
- 准备目录
mkdir -pv /opt/dockerfile/web/nginx
- 编写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
- 创建网页测试文件
vi /opt/dockerfile/web/nginx/index.html
<h1> docker nginx test, nginx container by dockerfile</h1>
- 打包网页测试文件
tar czvf html.tar.gz index.html
- 构建镜像
docker build -t chenjb/centos-nginx /opt/dockerfile/web/nginx/
[外链图片转存失败(img-cnxsBmYN-1568380277357)(png/2019-09-12-15-34-22.png)]
- 查看镜像
docker images
- 启动容器
docker run -it -d -p 80:80 --name "nginx-test" chenjb/centos-nginx
[外链图片转存失败(img-YYRhI3i7-1568380277358)(png/2019-09-12-15-39-05.png)]
- 查看进程
docker ps
- 测试网页
# curl localhost
<h1> docker ginx test, nginx container by dockerfile</h1>