I'm trying to access Redis server through the code and it's not connecting. But if i bash to the redis container i can access the redis-cli.
docker-compose.yml looks like this
version: '2'
services:
web:
build:
context: .
dockerfile: Dockerfile_nginx
ports:
- "9000:80"
environment:
- NGINX_SERVERNAME=xxx.dev *.xxx.dev
command: /bin/bash -c "envsubst '$$NGINX_SERVERNAME' < /var/www/site.template > /etc/nginx/conf.d/default.conf
&& dos2unix /var/www/provision/init_storage.sh && sh /var/www/provision/init_storage.sh
&& nginx -g 'daemon off;'"
volumes:
- .:/var/www
links:
- php
networks:
frontend
php:
build:
context: .
dockerfile: Dockerfile_php-fpm
command: /bin/bash -c "composer install
&& php-fpm"
volumes:
- .:/var/www
environment:
- APP_ENV=local
- APP_DEBUG=true
networks:
- frontend
- backend
links:
- redis
db:
build:
context: .
dockerfile: Dockerfile_mariadb
volumes:
- ./initdb:/docker-entrypoint-initdb.d
ports:
- "3309:3306"
environment:
MYSQL_ROOT_PASSWORD: xxxx
MYSQL_DATABASE: xxxx
networks:
- backend
redis:
build:
context: .
dockerfile: Dockerfile_redis
ports:
- "6379:6379"
networks:
frontend:
driver: bridge
backend:
driver: bridge
Dockerfile_redis
FROM redis:latest
When i try to connect to the redis server using this code
$redis = new \Redis();
try {
$redis->connect('127.0.0.1', 6379);
} catch (\Exception $e) {
var_dump($e->getMessage()) ;
die;
}
It gives this warning
Warning: Redis::connect(): connect() failed: Connection refused
Does anyone know how to connect Redis container to PHP container ?