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

docker-compose.yml

#指定Compose版本,目前有1/2/3三个版本
version: '3'

#服务
services:
  #服务名称
  php:
    #镜像名称
    image: registry.cn-beijing.aliyuncs.com/wang78699425/php
    #自定义容器名称
    container_name: myphp
    #重启规则,no,默认策略,在容器退出时不重启容器;on-failure,在容器非正常退出时(退出状态非0),才会重启容器 on-failure:5,在容器非正常退出时重启容器,最多重启5次;always,在容器退出时总是重启容器;unless-stopped,在容器退出时总是重启容器,但是不考虑在Docker守护进程启动时就已经停止了的容器
    restart: on-failure:5
    #端口映射
    ports:
      - 9000:9000
    #网络配置
    networks:
      #网络名称,与下面的网络对应
      mynetwork:
        #服务在网络中的别名,为了区分同一个网络中的多个服务
        aliases:
          - php
    #目录/文件挂载
    volumes:
      #宿主机的 /usr/local/php/php.ini 挂载到容器中的 /usr/local/php/php.ini
      - /usr/local/php/php.ini:/usr/local/php/php.ini
      - /usr/local/php/php-fpm.conf:/usr/local/php/php-fpm.conf
      - /usr/local/php/php-fpm-config:/usr/local/php/php-fpm-config
      - /var/www:/var/www
      - /var/log/php-fpm/:/var/log/php-fpm/
    #容器启动后默认执行的命令,这里使用/usr/sbin/init,不然容器内不能使用systemclt相关服务,会导致容器内的服务开机启动失败
    command: /usr/sbin/init
  nginx:
    image: registry.cn-beijing.aliyuncs.com/wang78699425/nginx
    container_name: mynginx
    restart: on-failure:5
    ports:
      - 80:80
    networks:
      mynetwork:
        aliases:
          - nginx
    volumes:
      - /usr/local/nginx/nginx.conf:/usr/local/nginx/nginx.conf
      - /usr/local/nginx/vhost:/usr/local/nginx/vhost
      - /var/www:/var/www
      - /var/log/nginx:/var/log/nginx
    command: /usr/sbin/init
  redis:
    image: registry.cn-beijing.aliyuncs.com/wang78699425/redis
    container_name: myredis
    restart: on-failure:5
    ports:
      - 6379:6379
    networks:
      mynetwork:
        aliases:
          - redis
    volumes:
      - /usr/local/redis/redis.conf:/usr/local/redis/redis.conf
      - /var/log/redis.log:/var/log/redis.log
    command: /usr/sbin/init
  mysql:
    image: registry.cn-beijing.aliyuncs.com/wang78699425/mysql
    container_name: mymysql
    restart: on-failure:5
    ports:
      - 3306:3306
    networks:
      mynetwork:
        aliases:
          - mysql
    volumes:
      - /usr/local/mysql/my.cnf:/etc/my.cnf
      - /usr/local/mysql/data:/var/lib/mysql
      - /var/log/mysqld.log:/var/log/mysqld.log
    command: /usr/sbin/init
#网络
networks:
  #网络名称,如果没有此网络,会新建
  mynetwork:
    #驱动
    driver: bridge


Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐