docker-compose配置

基础示例

version: '3'
services:
  mysql:
    image: mysql:5.7
    volumes:
      - /docker/etc/mysql:/var/lib/mysql
    ports:
      - 0.0.0.0:3306:3306
    environment:
      - MYSQL_ROOT_PASSWORD=abcde密码
      - TZ=Asia/Shanghai
    command:
      --character-set-server=utf8mb4
      --collation-server=utf8mb4_general_ci
    deploy: 
      resources: 
        limits: 
          memory: 2G
          cpus: '0.50'
  cscodercn:
    image: zbinweb:3.1
    volumes:
      - /docker/etc/cscoder.cn.3.1/:/web
    ports:
      - 0.0.0.0:12345:80
    environment:
      - TZ=Asia/Shanghai  # 最好加上,否则会出现时区问题
    logging: 
      driver: json-file
      options: 
        max-size: 1g    # 最好加上,否则会使得磁盘占满
  nginx:
    image: nginx:latest
    volumes:
      - /docker/etc/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
      - /docker/etc/nginx/other.d:/etc/nginx/other.d
    ports:
      - 0.0.0.0:80:80
      - 0.0.0.0:443:443
    links:
      - cscodercn

格式为YAML,将以上代码保存为 docker-compose.yml 即可使用

注意,由于v3后,不再支持deploy,那么如果加了deploy,up 会出现警告, 需要加 --compatibility 来规避

docker-compose --compatibility up -d

Compose file deploy reference | Docker Documentation