Answer the question
In order to leave comments, you need to log in
How to connect a local database in php in docker?
The docker-compose.yml file looks like
version: '3'
services:
nginx:
image: nginx:latest
ports:
- 9080:80
volumes:
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
- ./:/var/www/html
- ./logs:/var/log/nginx
depends_on:
- php
php:
build:
context: ./docker/php
ports:
- 9000:9000
volumes:
- ./:/var/www/html
- ./logs:/var/log/
- ./docker/php/php.ini:/usr/local/etc/php/php.ini
restart: always
extra_hosts:
- host.docker.internal:$DOCKER_HOST_IP
docker run --rm -it --network=host mysql php -h 127.0.0.1 -uroot -p
//$link = mysqli_connect('172.17.0.1', 'root', '1234qwer');
$link = mysqli_connect('127.0.0.1', 'root', '1234qwer');
if (!$link) {
echo "Ошибка: Невозможно установить соединение с MySQL." . PHP_EOL;
echo "Код ошибки errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Текст ошибки error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
bind-address = 127.0.0.1
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question