Este artigo descreve principalmente como usar o docker para instalar a imagem nginx e montar os arquivos no docker na máquina física
1. Baixe a imagem Nginx
docker pull nginx
2. Crie uma pasta de montagem localmente
/Users/zhanghao/data/nginx/conf/
/Users/zhanghao/data/nginx/conf.d/
/Users/zhanghao/data/nginx/html/
/Users/zhanghao/data/nginx/logs/
Nota: Crie de acordo com seu próprio caminho e use o diretório criado aqui para montar o comando de inicialização subsequente.
3. Inicie um contêiner não montado e copie o arquivo de configuração
docker run --name nginx-test -d -p 80:80 nginx
docker cp nginx-test:/etc/nginx/nginx.conf /Users/zhanghao/data/nginx/conf/nginx.conf
docker cp nginx-test:/etc/nginx/conf.d/default.conf /Users/zhanghao/data/nginx/conf.d/default.conf
docker cp nginx-test:/usr/share/nginx/html/50x.html /Users/zhanghao/data/nginx/html/
docker cp nginx-test:/usr/share/nginx/html/index.html /Users/zhanghao/data/nginx/html/
4. Feche e exclua o contêiner criado temporariamente
docker stop nginx-test
docker rm nginx-test
5. Inicie o contêiner montado
docker run --name nginx1 -p 80:80 -v /Users/zhanghao/data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /Users/zhanghao/data/nginx/conf.d:/etc/nginx/conf.d -v /Users/zhanghao/data/nginx/html:/usr/share/nginx/html -v /Users/zhanghao/data/nginx/logs:/var/log/nginx -d nginx
6. Teste
Visite a página de boas-vindas do nginx http:127.0.0.1
Link original: https://blog.csdn.net/qq_42114918/article/details/85238011