docker-compose.yml 文件指令介绍
https://yeasy.gitbooks.io/docker_practice/content/compose/compose_file.html

git 项目地址
https://github.com/Gekkoou/dnmp


目录结构

├── conf                         配置目录
│   ├── mysql                    MySQL配置文件目录
│   │   └── my.cnf               MySQL配置文件
│   ├── nginx                    Nginx配置文件目录
│   │   ├── conf.d               站点配置文件目录
│   │   │   └── default.conf     默认站点配置文件
│   │   └── nginx.conf           Nginx通用配置文件
│   └── php                      PHP配置目录
│       │── php.ini              PHP配置文件
│       └── php-fpm.conf         PHP-FPM配置文件
├── log                          日志目录
│   ├── mysql                    MySQL日志目录
│   ├── nginx                    Nginx日志目录
│   └── php                      PHP日志目录
├── mysql                        MySQL数据文件目录
├── php                          PHP目录
│   └── php56                    PHP5.6目录
│       └── Dockerfile           Dockerfile配置文件
├── www                          站点根目录
│   └── index.php                index文件
└── docker-compose.yml           docker-compose配置文件

使用

  1. 安装 dockerdocker-compose
  2. git clone 代码到本地

    $ git clone git@github.com:Gekkoou/dnmp.git
  3. 执行命令

    $ cd dnmp
    $ docker-compose up -d
  4. 默认站点在浏览器中访问 localhost

    phpmyadmin 访问 localhost:8080 , 帐号 root 密码 root

# docker-compose up -d
# docker ps -a
CONTAINER ID        IMAGE                          COMMAND                  CREATED             STATUS              PORTS                                      NAMES
dad39a530a83        phpmyadmin/phpmyadmin:latest   "/run.sh superviso..."   5 hours ago         Up 3 hours          9000/tcp, 0.0.0.0:8080->80/tcp             my-phpmyadmin
42cf670a099f        mysql:5.7                      "docker-entrypoint..."   5 hours ago         Up 3 hours          0.0.0.0:3306->3306/tcp                     my-mysql
9c832c8f271e        dnmp_php                       "php-fpm -F"             5 hours ago         Up 3 hours          9000/tcp                                   dnmp_php_1
ad61b06a4ec1        nginx:alpine                   "nginx -g 'daemon ..."   5 hours ago         Up 3 hours          0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp   my-nginx

重启 nginx
docker exec -it my-nginx nginx -s reloaddocker-compose restart nginx

重启 php-fpm
docker exec -it dnmp_php_1 kill -USR2 php-fpm的pid (例如 kill -USR2 99 或 kill -USR2 $(cat /var/run/php-fpm/php-fpm.pid))
docker-compose restart php

启动所有已经存在的服务容器
docker-compose start

停止所有已经处于运行状态的容器
docker-compose stop

重启所有已经存在的容器
docker-compose restart

删除所有 (停止状态的) 服务容器
docker-compose rm


docker-compose.yml 文件内容

version: "2"
services:
  nginx:
    image: nginx:alpine
    container_name: my-nginx
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./conf/nginx/conf.d/:/etc/nginx/conf.d/:ro
      - ./conf/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
      - ./log/nginx/:/var/log/nginx/:rw
      - ./www/:/var/www/:rw
    networks:
      - net-php

  php:
    build: ./php/php56/
    expose:
      - "9000"
    volumes:
      - ./conf/php/php.ini:/etc/php/php.ini:ro
      - ./conf/php/php-fpm.conf:/etc/php/php-fpm.conf:ro
      - ./log/php/:/var/log/php/:rw
      - ./www/:/var/www/:rw
    networks:
      - net-php
      - net-mysql

  mysql:
    image: mysql:5.7
    container_name: my-mysql
    ports:
      - "3306:3306"
    volumes:
      - ./conf/mysql/my.cnf:/etc/mysql/my.cnf:ro
      - ./log/mysql/:/var/log/mysql/:rw
      - ./mysql/:/var/lib/mysql/:rw
    environment:
      MYSQL_USER: "root"
      MYSQL_PASSWORD: "root"
      MYSQL_ROOT_PASSWORD: "root"
    networks:
      - net-mysql

  phpmyadmin:
    image: phpmyadmin/phpmyadmin:latest
    container_name: my-phpmyadmin
    ports:
      - "8080:80"
    environment:
      MYSQL_USER: "root"
      MYSQL_PASSWORD: "root"
      MYSQL_ROOT_PASSWORD: "root"
      PMA_HOST: my-mysql
    networks:
      - net-mysql

networks:
  net-php:
  net-mysql:





Logo

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

更多推荐