Docker-compose yaml模板

Docker-compase yaml模板 以wordpress 为例

version: '3'  # 版本为123,已docker engine为例,一般为3 docker1.10之前为1
services: 
  db:        # docker-compase控制的name
    container_name: mysql  # 容器名字
    image: mysql:5.7  # 容器镜像
    volumes:  # 挂载路径
    - db_data:/var/lib/mysql
    restart: always # 自启
    environment:  # 变量
      MYSQL_ROOT_PASSWORD: wordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
    networks:  # 定义网络
    - net_wordpress

  wordpress:
    depends_on:  # 依赖于db 相关的容器 db启动后在启动这个 
    - db
    image: wordpress:latest
    links:
    - db     # 网络关联 db 相关联的容器
    volumes:
    - wp_site:/var/www/html
    ports:
    - "80:80"
    - "443:443"
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
    networks:  # 定义网路,上面已经关联db相关的网络,此项可以省略
    - net_wordpress

volumes:   # 挂载的存储
  db_data:
  wp_site:

networks:  # 定义网络
  net_wordpress: 
    driver: bridge  # 桥接模式 
 

你可能感兴趣的:(Docker,杂七杂八,docker,容器,mysql)