docker-compose 部署 nginx + php-fpm + mysql + phpmyadmin
docker-compose.yml 文件指令介绍https://yeasy.gitbooks.io/docker_practice/content/compose/compose_file.htmlgit 项目地址https://github.com/Gekkoou/dnmp目录结构├── conf配置目录│├─...
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配置文件
使用
- 安装
docker
和docker-compose
- git clone 代码到本地
$ git clone git@github.com:Gekkoou/dnmp.git
- 执行命令
$ cd dnmp
$ docker-compose up -d
默认站点在浏览器中访问
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 reload
或 docker-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:
更多推荐
所有评论(0)