I have legacy PHP application. It used mysqli to make mysql things. So in config I have DSN string to connect to mysql service. Like that
mysql://username:password@db_hostname/dbname
Mysqli returns error
Warning: mysqli::real_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known
But if I will try connect by hand using this
mysqli::real_connect("db_hostname")
It says Warning: mysqli::real_connect(): (HY000/1045): Access denied for user ''@'172.21.0.3' (using password: NO)
real_connect("user@db_hostname")
, real_connect("mysql:db_hostname")
, real_connect("mysql:host=db_hostname")
can not resolve host address.
What I'm doing wrong?
docker-compose.yml:
version: "3"
services:
nginx:
image: nginx:1.13-alpine
volumes:
- ./docker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf:ro
- ./docker/nginx/errors.log:/var/logs/errors.log
- ./docker/nginx/access.log:/var/logs/access.log
- ./:/var/www/html
ports:
- "8081:80"
command: nginx -g "daemon off;"
php:
build:
context: ./docker/
dockerfile: php.Dockerfile
user: "1000"
volumes:
- ./docker/timezone.php.ini:/usr/local/etc/php/conf.d/timezone.php.ini:ro
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
- ./:/var/www/html
db_hostname:
image: mysql:5.5
user: "1000"
environment:
- MYSQL_DATABASE=db
- MYSQL_ROOT_PASSWORD=root
- MYSQL_USER=user
- MYSQL_PASSWORD=user
volumes:
- ./docker/mysql:/var/lib/mysql
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro