docker使用 docker-compose配置PHP环境(php+nginx+mysql)及启动

             

docker-compose启动

docker-compose是docker三剑客之一,用来专门启动镜像的插件,可以通过pip install docker-compose安装。

可以新建一个如下目录结构的文件夹,作为镜像的启动文件夹:

编写docker-compose.yml文件(启动三个容器):

version: "3.1"
services:
    nginx:
      image: nginx:latest
      container_name: nginx
      working_dir: /application
      volumes:
          - .:/application
          - ./config/nginx/conf.d:/etc/nginx/conf.d
         # - ./config/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
      ports:
       - "80:80"
      tty: true


    php-fpm:
      image: php-fpm:latest
      cap_add:
        - SYS_PTRACE
      container_name: php-fpm
      working_dir: /application
      volumes:
        - .:/application
        - ./config/php-fpm/php-ini-overrides.ini:/etc/php/7.3/fpm/conf.d/99-overrides.ini
        - ./config/php-fpm/www.conf:/etc/php/7.3/fpm/pool.d/www.conf
      tty: true


    mysql:
      image: mysql:latest
      container_name: mysql
      working_dir: /application
      volumes:
        - .:/application
        # config
        - ./config/mysql/conf.d:/etc/mysql/conf.d
        # datadir
        - ./datadir/mysql/data:/var/lib/mysql
      restart: always
      environment:
        - MYSQL_ROOT_PASSWORD=password
        - MYSQL_DATABASE=qhdata
        - MYSQL_USER=qhdata
        - MYSQL_PASSWORD=password
        - TZ=Asia/Shanghai
      ports:
        - "10002:3306"
      tty: true

启动:

切换到docker-compose.yml所在目录下执行:

docker-compose up即可启动镜像



发表评论 请登录再评论
  •   文章分类
回到顶部