[root@node-2 ~]# mkdir /opt/nginx
[root@node-2 ~]# cd /opt/nginx/
## 创建Dockerfile文件(Dockerfile 开头字母必须大写):
vim Dockerfile
#
# docker web images
FROM centos:latest
RUN yum install epel-release -y
RUN yum install nginx -y
EXPOSE 80 443 8080
CMD ["/usr/sbin/nginx","-g","daemon off;"] ## 没有添加环境变量进去 只能写全路径
## 生成Dockerfile镜像:
docker build -t nginx:v1 . ## 最后有个点 很重要
## 查看生成的docker images:
[root@node-2 nginx]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx v1 ad4850303e64 3 minutes ago 333MB
centos latest 831691599b88 3 weeks ago 215MB
## 从生成的镜像运行一个容器:
docker run -ti --rm -p 80:80 nginx:v1
## 访问 这个容器的IP :
http://ip/
## 确认镜像里面的nginx 代码目录在哪里:
docker run -ti --rm -p 80:80 nginx:v1 bash
vim /etc/nginx/nginx.conf
## 修改Dockerfile 文件:
vim Dockerfile
#
# docker web images
FROM centos:latest
RUN yum install epel-release -y
RUN yum install nginx -y && rm -rf /usr/share/nginx/html/*
ADD code.tar.gz /usr/share/nginx/html/
EXPOSE 80 443 8080
CMD ["/usr/sbin/nginx","-g","daemon off;"] ## 没有添加环境变量进去 只能写全路径
## 构建镜像:
docker build -t nginx:v2 .
## 生成容器:
docker run -ti --rm -p 80:80 nginx:v2 bash
## 访问:
curl http://IP
......查看内容即可
#!/bin/bash
TAG=$1
docker build -t nginx:$TAG .
### 上传harbor:
#docker push ........
### 运行脚本:
1 ) sh docker_build.sh 20200715
2 ) docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx 20200715 dd0aea4c4b95 3 days ago 333MB
原文:https://www.cnblogs.com/zhenxing06/p/13398657.html