mkdir nginx
cd nginx
mkdir logs html conf
cd conf
vim nginx.conf
worker_processes 1;

events {
    worker_connections 1024;
}

http {
    server {
        listen 80;
        server_name localhost;

        location / {
            root /usr/share/nginx/html;
            index index.html;
        }

        # 自定义错误页面
        error_page 404 /404.html;
        location = /404.html {
            internal;
        }
    }
}
cd ~/nginx
vim docker-compose.yml
version: '3'
services:
  nginx:
    image: nginx
    container_name: my-nginx
    ports:
      - "80:80"
    volumes:
      - ~/nginx/html:/usr/share/nginx/html
      - ~/nginx/conf/nginx.conf:/etc/nginx/nginx.conf
      - ~/nginx/logs:/var/log/nginx
docker compose up -d