【Docker】之安装Nginx

拉取镜像

docker pull nginx:1.22

创建目录

mkdir -p /root/docker/nginx/{www,logs,conf}

创建容器

docker run -p 80:80 --name nginx \
-v /root/docker/nginx/html:/usr/share/nginx/html \
-v /root/docker/nginx/nginx.conf:/etc/nginx/nginx.conf \
-v /root/docker/nginx/conf.d:/etc/nginx/conf.d \
-v /root/docker/nginx/logs:/var/log/nginx \
-d nginx:1.22

复制Nginx配置

docker cp nginx:/etc/nginx/nginx.conf /root/docker/nginx/conf

www目录下创建index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>docker搭建nginx</title>
</head>
<body>
    <h1>docker搭建nginx映射成功</h1>
    <p>test</p>
</body>
</html>

Docker-compose.yaml

version: "3.9"
    
services:
  web:
    image: nginx:1.22
    container_name: nginx
    restart: always
    ports: 
    	- 80:80
    volumes:
      >>>>>
      >>>>>