1. Pull the mirror

docker pull nginx:latest
Copy the code

Quick installation

docker run --name nginx -d -p 80:80 nginx:latest
Copy the code

Copy configuration files to host host (nginx root directory /data/nginx)

docker cp nginx:/etc/nginx/nginx.conf /data/nginx/
docker cp nginx:/etc/nginx/conf.d /data/nginx/
docker cp nginx:/usr/share/nginx/html /data/nginx/
Copy the code

The new directory

mkdir log cert
Copy the code

2. Use the customized configuration file for startup

docker run \
--name nginx \
-e HOST_Q=$(hostname) \
-d -p 80:80 -p 443:443 \
-v /data/nginx/nginx.conf:/etc/nginx/nginx.conf \
-v /data/nginx/log:/var/log/nginx \
-v /data/nginx/html:/usr/share/nginx/html \
-v /data/nginx/cert:/etc/nginx/cert \
-v /data/nginx/conf.d:/etc/nginx/conf.d \
nginx:latest
Copy the code

/data/nginx service configuration :conf.d Certificate :cert