pklndnst
pklndnst

Reputation: 756

Docker compose fails to setup container links properly

I recently started with Docker Compose and followed the introductions of the official docs. The first example I did (see here) defines two containers inside docker-compose.yml and if I understand them right, the containers are linked by default. Their .yml looks the same as mine:

version: '2'
services:
  web:
    build: .
    ports:
    - "5000:5000"
    volumes:
    - .:/code
    depends_on:
    - redis
  redis:
   image: redis

However, using docker exec in order to take a look inside the running web container reveals that there's no DNS entry for redis in /etc/hosts. I'm also not capable of doing a ping to the redis container by name, it only works for the container's IP address. This is my /etc/hosts:

127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback 
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.18.0.3      e886da2c2a78

I've also examined the bug reports at Github, but the suggestions I found didn't work for me so far. I can exclude the possibility that is has to do with any firewall issues, since firewalld is not running on my host.

Any ideas?

My setup:

Upvotes: 0

Views: 1609

Answers (1)

larsks
larsks

Reputation: 311526

I'm using:

$ docker --version
Docker version 1.11.1, build 5604cbe

If I use your docker-compose.yml file verbatim, and the following Dockerfile to give docker-compose something to build:...

FROM alpine
RUN apk add --update darkhttpd
CMD ["darkhttpd", "/var/www/localhost/htdocs"]

Then I start everything up:

$ docker-compose up -d

And then enter the web container:

$ docker exec -it outofbounds_web_1 sh

And then ping redis:

/ # ping -c 1 redis
PING redis (172.20.0.2): 56 data bytes
64 bytes from 172.20.0.2: seq=0 ttl=64 time=0.166 ms

--- redis ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max = 0.166/0.166/0.166 ms

It all Just Works.

As was mentioned in the comments, there are no modifications to /etc/hosts because name resolution is now handled via dns lookups.

Upvotes: 2

Related Questions