docke安装nginx

1、拉取镜像

docker pull nginx:1.25.4

2、配置nginx路径

mkdir -p /data/nginx/html
mkdir -p /data/nginx/log
mkdir -p /data/nginx/conf

3、启动nginx

docker run -p 80:80 -d --name nginx nginx:1.25.4
#拷贝配置,容器ID查看命令:docker ps
docker cp fdafd05e248c:/etc/nginx/nginx.conf /data/nginx/conf/nginx.conf
docker cp fdafd05e248c:/etc/nginx/conf.d /data/nginx/conf/conf.d
docker cp fdafd05e248c:/usr/share/nginx/html /data/nginx

4、重启nginx

#停止容器
docker stop fdafd05e248c
#删除容器
docker rm fdafd05e248c
#启动nginx
docker run -d -p 80:80 --name nginx --privileged --restart always \
-v /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /data/nginx/conf/conf.d:/etc/nginx/conf.d \
-v /data/nginx/html:/usr/share/nginx/html \
-v /data/nginx/log:/var/log/nginx \
nginx:1.25.4
posted @ 2024-08-01 17:53  Sdy8571  阅读(7)  评论(0编辑  收藏  举报