这是我的docker-compose
version: '2'
services:
nginx:
image: nginx:1.11.8-alpine
ports:
- "8081:80"
volumes:
- ./code:/usr/share/nginx/html
- ./html:/myapp
- ./site.conf:/etc/nginx/conf.d/site.conf
- ./default.conf:/etc/nginx/conf.d/default.conf
- ./error.log:/var/log/nginx/error.log
- ./nginx.conf:/etc/nginx/nginx.conf
links:
- phpfpm
phpfpm:
image: php7-fpm:latest
ports:
- "9000:9000"
volumes:
- ./code:/usr/share/nginx/html
links:
- db_mysql
db_mysql:
image: mysql:5.7.17
volumes:
- db_data:/var/lib/mysql
# restart: no
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: wp2017
MYSQL_USER: wp
MYSQL_PASSWORD: wp2017
volumes:
db_data:
这是我如何构建自己的php7-fpm:lastest
FROM php:7.1-fpm-alpine RUN docker-php-ext-install mysqli
我无法连接到mysql容器
$serverName = 'localhost'; $userName = 'wp'; $password = 'wp2017'; $dbName = 'wp2017'; $link = mysqli_connect($serverName, $userName, $password, $dbName); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); }
我总是得到错误:"警告:mysqli_connect():( HY000/2002):第8行/usr/share/nginx/html/db.php中没有这样的文件或目录连接失败:没有这样的文件或目录"
我在哪里运行命令sudo netstat -tulpn | grep:3306
我得到这个tcp6 0 0 ::: 3306 :::*LISTEN 15362/docker-proxy
请帮忙 !
更改PHP脚本
$serverName = 'db_mysql';
它会工作.