1. Download nginx image
docker pull nginx
或者
docker pull nginx:1.21.1
2. Create nginx mapping file directory
mkdir -p /home/nginx/conf
mkdir -p /home/nginx/log
mkdir -p /home/nginx/html
3. Copy the files in the container to the host
# 生成容器
docker run --name nginx -p 8090:80 -d nginx
Copy the container configuration file, html deployment file, and log file
docker cp nginx:/etc/nginx/nginx.conf /home/nginx/conf/nginx.conf
docker cp nginx:/etc/nginx/conf.d /home/nginx/conf/conf.d
docker cp nginx:/usr/share/nginx/html /home/nginx/
then delete the container
docker rm -f nginx
4. Modify the configuration file
cd /home/nginx/conf/conf.d
vim default.conf
The content of default.conf is as follows
server {
listen 10082;
listen [::]:10082;
server_name localhost;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location ^~ /api/ {
#测试环境
#proxy_pass http://xx.xx.xx.xx:18020/;
# 生产环境
proxy_pass http://xx.xx.xx.xx:18020/;
}
}
5. Deploy the front-end package
cd /home/nginx/html
rz -ry
Upload front-end package
6. Start the container
docker run \
-p 8090:10082\
--name jk-nginx \
-v /home/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /home/nginx/conf/conf.d:/etc/nginx/conf.d \
-v /home/nginx/log:/var/log/nginx \
-v /home/nginx/html:/usr/share/nginx/html \
-d nginx:latest
7. Test
Visit http://xx.xx.xxx.xx:8090/
Check whether the background url is correct
8. Generate Tar package
View container id
docker ps
Copy the container id to generate a mirror image
docker commit -m "my-nginx" -a "eric" 容器id my-nginx:1.0
Generate tar
docker save -o /home/my-nginx.tar my-nginx:1.0
Just download the tar from the server
9. Deploy the update
Modify the conf and html mapped by the host
Repeat step 8 and re-brand as tar
10. Intranet update
Just publish tar to Alibaba Cloud or Huawei Cloud