I'm trying to connect PHP with redis using docker (compose)
docker-compose.yml
version: '2'
services:
redis:
image: redis:3.2.2
php:
image: company/php:dev7
volumes:
- .:/var/www/
networks:
- net
links:
- redis
nginx:
image: company/nginx
volumes:
- .:/var/www/
- ./docker/nginx_conf:/etc/nginx/conf.d/
networks:
- net
ports:
- 80:80
networks:
net:
driver: bridge
This all works well and I'm able to run nginx and php. However when I'm trying to connect with Redit it tells me it cannot get the address info:
Fatal error: Uncaught Predis\Connection\ConnectionException: php_network_getaddresses: getaddrinfo failed: Name or service not known [tcp://redis:6379] in /var/www/htdocs/vendor/predis/predis/src/Connection/AbstractConnection.php on line 155
This is the way I'm trying to connect:
$client = new \Predis\Client([
'host' => 'redis',
]);
Also when I look into the redis docker container and look into /etc/hosts there is no redis hostname. At least I was expecting it over here as I'm trying to link it in the docker-compose.yml.
What do I configure wrong?