Docker – HAProxy 1.7 not resolving docker 1.13.1 container

dockerhaproxy

docker ps -a:

de09facf7c91        x/x:x   "/usr/bin/supervisord"   51 minutes ago      Up 24 minutes       8080/tcp                                                                           development-karl
226a1b80a233        x/x:x                                      "/usr/bin/supervisord"   2 hours ago         Up About a minute   0.0.0.0:80-84->80-84/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:1988->1988/tcp, 5672/tcp   haproxy

Started the container with this: docker run --name development-karl -h development-karl -d x/x:x

part of my haproxy.cfg:

backend karl_dev_backend
    balance roundrobin
    option forwardfor
    server      karl_dev development-karl cookie development-karl weight 1 maxconn 1024 check

Get the error in the haproxy logs:

[ALERT] 059/222244 (683) : parsing [/etc/haproxy/haproxy.cfg:67] : 'server karl_dev' : could not resolve address 'development-karl'.
[ALERT] 059/222244 (683) : Failed to initialize server(s) addr.

I don't know why it's not resolving?

EDIT, added answer info:

https://docs.docker.com/engine/userguide/networking/#the-default-bridge-network-in-detail:

Docker does not support automatic service discovery on the default
bridge network. If you want to communicate with container names in
this default bridge network, you must connect the containers via the
legacy docker run –link option.

Legacy is pre version 1.10.

Legacy: https://docs.docker.com/engine/userguide/networking/default_network/dockerlinks/

More info on legacy linking: https://docs.docker.com/engine/userguide/networking/work-with-networks/#linking-containers-without-using-user-defined-networks

Best Answer

I don't believe DNS discovery is enabled on the default docker bridge network. To connect multiple containers together with DNS discovery, create a network and attach both containers to that network:

docker network create proxy
docker network connect proxy haproxy
docker network connect proxy development-karl

You can also pass --net proxy to the docker run command instead of doing the docker network connect after the fact.

Related Topic