I am using docker compose to start both a registry and a linked redis container to use for the registry’s cache. However, I’m noticing that the docker registry is not able to connect to redis when I use the linked container as the hostname for the redis server.
Here’s my docker-compose.yml
version: '2'
services:
registry:
depends_on:
- redis
container_name: registry
image: registry:2.5.1
ports:
- "5000:5000"
volumes:
- ./config.yml:/etc/docker/registry/config.yml
redis:
container_name: redis
image: redis:latest
expose:
- "6379"
volumes:
- ./redis:/data
command: redis-server --appendonly yes
If I docker exec on to the running container, I can ping the hostname redis just fine. It returns an IP in the range of 172.x.x.x. If I then docker exec on to the running redis server, I see that the IP address returned by the ping matches the one in its /etc/hosts.
The only way I’ve gotten the registry to be able to connect to redis without timing out is to hard-code that IP address in the registry’s config.yml. However, I know hard-coding IP addresses in docker is not ideal. I’ve also tried using link aliases and setting the link explicitly in the docker-compose.yml.
I’ve also verified that the redis server itself works by bringing up the containers with compose and then linking a container manually with redis-cli installed. I can use redis’ ping against the “redis” hostname just fine.
Am I doing something wrong? Or am I misunderstanding how docker links containers?