文档结构
.
├── docker-compose.yml
├── mysql
│ └── Dockerfile
├── nginx
│ ├── conf
│ │ └── default.conf
│ └── Dockerfile
├── php
│ └── Dockerfile
└── www
├── 1.txt
└── test.php
docker-compose.yml
version: '2'
services:
nginx:
image: nginx:1
ports:
- "80:80"
links:
- phptest
volumes:
- /opt/nginx/conf/default.conf:/etc/nginx/conf.d/default.conf
- /opt/www:/var/www
phptest:
image: php:7.2.10-fpm
container_name: phptest
ports:
- "9000:9000"
privileged: true
volumes:
- /opt/www:/var/www/html
depends_on:
- "mysql"
mysql:
image: mysql:5.7
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: 123456
nginx
default.conf
upstream phpupstream {
server phptest:9000 fail_timeout=5s max_fails=5;
}
server {
listen 80;
server_name localhost;
location / {
root /var/www; # 代码目录
index index.html index.htm index.php; # 增加index.php
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html;
}
location ~ \.php$ {
root /var/www/html/; # 代码目录
fastcgi_pass phpupstream; # 修改为php容器(compose文件中nginx段设置的links的php名称)
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # 修改为$document_root
include fastcgi_params;
}
}
解决问题
mysql 报错 没有想过函数
// 进入容器
docker exec -it php-container-name /bin/bash
// 切换目录
cd /usr/local/bin
// 安装pdo_mysql扩展
./docker-php-ext-install pdo_mysql
// 安装mysqli扩展
./docker-php-ext-install mysqli
// 退出容器
exit
// 重启容器
docker restart php-container-name