2
這裏是我的碼頭工人,組成PHP無法連接到MySQL的碼頭工人,組成
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:最新的
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 /泊塢窗代理
請幫幫忙!
http://stackoverflow.com/questions/4219970/warning-mysql-connect-2002-no-such-file-or-directory-trying-to-connect-vi – Pingbeat
會嘗試使用您的本地IP進行連接首先。 – Pingbeat
我也無法連接。 我在本地安裝了一個mysql服務器(Ubuntu 14.04),但我已經停止了它。 似乎這是理由? –