-
下载nginx镜像
docker pull nginx:1.24.0
-
简易启动nginx
docker run -p 81:80 -d --name simple-nginx nginx:1.24.0
-
创建本地挂载文件夹
#创建四个文件夹conf,log,html,conf.d mkdir -p /home/nginx/{conf,logs,html,conf.d}
-
复制简易nginx中的文件到挂载目录中
#复制页面文件 docker cp nginx:/usr/share/nginx/html /home/nginx/ #复制nginx配置文件 docker cp nginx:/etc/nginx/nginx.conf /home/nginx/conf/ #复制conf.d文件 docker cp nginx:/etc/nginx/conf.d /home/nginx/
-
启动nginx
docker run -p 80:80 \ -v /home/nginx/conf/nginx.conf:/etc/nginx/conf/nginx.conf \ -v /home/nginx/logs:/var/log/nginx \ -v /home/nginx/html:/usr/share/nginx/html \ -v /home/nginx/conf.d:/etc/nginx/conf.d \ -v /etc/localtime:/etc/localtime \ --name nginx \ --restart=always \ -d nginx:1.24.0
-
访问ip测试是否成功