I'm trying to mount a generic project based on this docker image and everything works correctly when creating the containers and launch them, the database is accessible from PHPMyAdmin and PHP is launched correctly.
The problem comes when I try to make a connection to the database. It is due to a permissions problem on the volume that is mounted - ./data/db/mysql:/var/lib/mysql
. When trying to make a connection in a PHP it throws me the error Warning: mysqli::__construct(): (HY000/2002): No such file or directory in
The connection I am making is such that:
$conn = new mysqli(
$settings['db_host'],
$settings['db_username'],
$settings['db_password'],
$settings['db_name']
);'
What little I have found mentions some permission; although it seems that when trying to make the connection with the BBDD you need write permission on that directory. I have also read that there is a problem with PHP-FPM and permissions with Docker .
This is my docker-compose.yml:
version: '3'
services:
web:
image: nginx
volumes:
- "./etc/nginx/default.conf:/etc/nginx/conf.d/default.conf"
- "./etc/ssl:/etc/ssl"
- "./web:/var/www/html"
- "./etc/nginx/default.template.conf:/etc/nginx/conf.d/default.template"
ports:
- "8000:80"
- "3000:443"
environment:
- NGINX_HOST=${NGINX_HOST}
command: /bin/bash -c "envsubst '$$NGINX_HOST' < /etc/nginx/conf.d/default.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"
restart: always
depends_on:
- php
- mysqldb
php:
image: nanoninja/php-fpm
restart: always
volumes:
- "./etc/php/php.ini:/usr/local/etc/php/conf.d/php.ini"
- "./web:/var/www/html"
composer:
image: "composer"
volumes:
- "./web/app:/app"
command: install
myadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
ports:
- "8080:80"
environment:
- PMA_ARBITRARY=1
- PMA_HOST=${MYSQL_HOST}
restart: always
depends_on:
- mysqldb
mysqldb:
image: mysql
container_name: ${MYSQL_HOST}
restart: always
env_file:
- ".env"
environment:
- MYSQL_DATABASE=${MYSQL_DATABASE}
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
ports:
- "8989:3306"
volumes:
- "./data/db/mysql:/var/lib/mysql"'
Perhaps the most important thing is now, the docker works on Windows 10 PRO with HyperV and a VMachine with Alpine Linux v3.5.