I'm learning Docker and am still pretty new to it. I'm trying to get PHP 7 FPM, Nginx and MariaDB to work together ( I'm using this version of PHP 7 FPM because it come with MySQLi already installed) but I receive the following error:
Warning: mysqli_connect(): (HY000/2002): No such file or directory in /usr/share/nginx/html/index.php on line 4
Error: Unable to connect to MySQL. Debugging errno: 2002 Debugging error: No such file or directory
My index.php looks like this:
<?php
header('Content-Type: application/json');
$link = mysqli_connect("localhost", "admin", "admin", "admin");
if (!$link) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL;
echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;
mysqli_close($link);
and my Dockerfile looks like this:
version: '2'
services:
nginx:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./nginx/site.conf:/etc/nginx/conf.d/default.conf
- ./logs/nginx-error.log:/var/log/nginx/error.log
- ./logs/nginx-access.log:/var/log/nginx/access.log
- ./public:/usr/share/nginx/html
links:
- php:php
php:
image: danieldent/php-7-fpm
volumes:
- ./public:/usr/share/nginx/html
- ./logs/log.conf:/usr/local/etc/php-fpm.d/zz-log.conf
- ./PHP/php.ini:/etc/php/7.0/fpm/php.ini
- ./PHP/php.ini:/usr/local/etc/php/conf.d/php.ini
links:
- mariadb:mysqlip
mariadb:
image: mariadb:latest
environment:
MYSQL_ROOT_PASSWORD: pw
stdin_open: true
tty: true
ports:
- 3306:3306/tcp
labels:
io.rancher.container.pull_image: always
volumes:
- ./database:/var/lib/mysql
phpmyadmin:
image: phpmyadmin/phpmyadmin
links:
- mariadb:db
The php_mysqli.dll extension is also enabeled in my php.ini file.
Again I'm still pretty new to docker but really want to get this working, thanks for any suggestions.