docker 安装nginx

时间:2024-04-04 17:42:01

一、先查看有没有nginx镜像

docker images

二、发现没有nginx镜像,下载最新镜像

docker pull nginx

三、运行镜像

为了先复制出部分文件,先启动一个临时容器

docker run --name nginx -p 9001:80 -d nginx
docker cp nginx:/etc/nginx/conf.d /home/wxb/application/nginx/conf.d/
docker cp nginx:/etc/nginx/nginx.conf /home/wxb/application/nginx/nginx.conf
docker cp nginx:/usr/share/nginx/html /home/wxb/application/nginx/html
docker stop nginx
docker rm nginx
docker run -d -p 80:80 -d -p 443:443 --name nginx --restart=always \
-v /home/wxb/application/nginx/conf.d:/etc/nginx/conf.d \
-v /home/wxb/application/nginx/nginx.conf:/etc/nginx/nginx.conf \
-v /home/wxb/application/nginx/html/:/usr/share/nginx/html/ \
-v /home/wxb/application/nginx/logs:/var/log/nginx \
-v /home/wxb/application/nginx/cert/:/etc/nginx/cert/ \
nginx

四、查看运行结果

docker ps