Docker Community Forums

Share and learn in the Docker community.

PHP-FPM linked container not found by hostname

docker

(Hryhorii Furletov) #1

Docker hosts problem

Hi guys!

I have 3 docker-containers: nginx:1.13 (nginx), php:7.1-fpm (php) and mariadb:10.3 (db).
I have php-script for connect to the database and output result for connected status: failed | success.
I use linked container in php-fpm container with name db.
If php-script run in php-fpm (via nginx) - connect to the database failed, because host db is unknown.
If php-script run in console (in php-fpm container) - connect to the database success.

Why???


(Hryhorii Furletov) #2

@aios
docker-compose exec php sh -c "php /var/www/testdb.php" - connect success
curl http://localhost/testdb.php - failed

answer:

en I commented line chroot = /scripts in php-fpm pool config file - conect to the database host db success.
php-fpm pool has not access to check /etc/hosts file, but chroot config set chroot important.

ru Хочу поделится решением.
Мы знаем, что хост db в php контейнере прописан здесь: /etc/hosts.
В настройках php-fpm я указал chroot = /scripts (php работает в рамках этой директории.)
Когда я убрал конфиг chroot = /scripts, то успешно подключился к базе данных через хост db.
Так что аккуратно играйте с настройкой chroot в php-fpm :slight_smile: