docker compose yml 文件编写

xxxx.yml (YAML)编写版本 有 version 1、version 2、version 3;当前用 version 3 的方式编写
当前 V3 格式 与docker的版本 支持请查看:https://docs.docker.com/compose/compose-file/

centos 安装 docker-compose

yum install -y docker-compose

# 查看版本
docker-compose --version

实例:gogs的docker 配置文件 gogs-compose.yml

  • 配置yaml 编写版本为 V2
  • 配置容器名称为 gogs_it513
  • 配置docker 镜像文件 gogs/gogs:latest
  • 配置本地端口映射
  • 配置挂载的对应文件夹
  • 指定加入的网络 并设置静态IP
  • 指定DNS服务器地址
  • 指定默认时区
version: '2'
services:
    gogs:
      container_name: gogs_it513
      image: 'gogs/gogs:latest'
      ports:
        - "20022:20022"
        - "23000:3000"
      volumes:
        - /volume3/docker/gogs/data:/data
        - /volume3/docker/gogs/app:/app
      networks:
        web:
          ipv4_address: 192.168.2.1
      dns: 192.168.1.1
      environment:
        TZ: 'Asia/Shanghai'
      restart: always
    mysql:
      container_name: mysql_it513
      image: 'mysql:5.7.25'
      ports:
        - "23306:3306"
      volumes:
        - /volume3/docker/mysql/data:/var/lib/mysql
        - /volume3/docker/mysql/logs:/var/log/mysql
      networks:
        web:
          ipv4_address: 192.168.2.2
      environment:
        MYSQL_ROOT_PASSWORD: mysql@it513
        TZ: 'Asia/Shanghai'
      restart: always
networks:
  web:
    driver: 'bridge'
    ipam:
      config:
        - subnet: 192.168.2.0/24
          gateway: 192.168.2.254

执行配置文件命令

docker-compose -f gogs-compose.yml up -d

继承已存在的网络

networks:
web:
external:
name: docker_web


version: '2'
services:
    gogs:
      container_name: gogs_itzh
      image: 'gogs/gogs:latest'
      ports:
        - "10022:10022"
        - "3000:3000"
      volumes:
        - /mnt/server/docker/gogs/mnt:/mnt
      networks:
        web:
          ipv4_address: 192.168.20.10
      environment:
        TZ: 'Asia/Shanghai'
      restart: always
networks:
  web:
    external:
        name: docker_web



你可能感兴趣的:(docker compose yml 文件编写)