version: '3.8'
services:
nginx:
image: nginx:latest
container_name: nginx # 容器名称
restart: always # 自动重启
ports:
- "80:80" # 映射端口
deploy:
resources:
limits:
cpus: "0.5" # 限制 CPU 核心数
memory: "512M" # 限制内存大小
volumes:
- nginx_html:/usr/share/nginx/html # 数据持久化
- nginx_conf:/etc/nginx/conf.d # 配置持久化
volumes:
nginx_html:
nginx_conf:
启动
docker compose up -d