resolve internal DNS in linked docker containers

I build two base images via:

docker build --tag dw_web web/
docker build --tag dw_db db/

and start the db container via:

  • Visual C++ for Linux Development + Docker
  • Run multiple containers on same docker network localhost
  • Keyboard/Mouse are unresponsable when running x-org in a docker container
  • How to list available storage drivers in docker?
  • Selenium cannot find file running in separate container
  • Docker, and small production server infrastructure advices
  • docker run -d --publish 3306:3306 --name dw_db_1 dw_db
    

    When I start the web container via the following command I cannot ping my db container:

    $ docker run -ti --rm --publish 8181:80 --link dw_db_1:dbsrv --name dw_web_1 dw_web /bin/bash
    
    root@ccd4ad5f0ae4:/# env
    HOSTNAME=ccd4ad5f0ae4
    TERM=dumb
    DBSRV_NAME=/dw_web_1/dbsrv
    DBSRV_ENV_DEBIAN_FRONTEND=noninteractive
    LC_ALL=en_US.UTF-8
    LS_COLORS=
    DBSRV_ENV_LC_ALL=en_US.UTF-8
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    PWD=/
    DBSRV_PORT=tcp://172.17.0.3:3306
    DBSRV_PORT_3306_TCP_PORT=3306
    LANG=en_US.UTF-8
    DBSRV_PORT_3306_TCP_ADDR=172.17.0.3
    DBSRV_PORT_3306_TCP=tcp://172.17.0.3:3306
    DBSRV_PORT_3306_TCP_PROTO=tcp
    DBSRV_ENV_LANG=en_US.UTF-8
    SHLVL=1
    HOME=/root
    DEBIAN_FRONTEND=noninteractive
    LESSOPEN=| /usr/bin/lesspipe %s
    LESSCLOSE=/usr/bin/lesspipe %s %s
    DBSRV_ENV_TERM=dumb
    _=/usr/bin/env
    root@ccd4ad5f0ae4:/# 
    root@ccd4ad5f0ae4:/# cat /etc/hosts 
    172.17.0.4  ccd4ad5f0ae4
    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.17.0.3  dbsrv d7814795da3c dw_db_1
    root@ccd4ad5f0ae4:/# ping dbsrv
    ping: unknown host dbsrv
    root@ccd4ad5f0ae4:/# 
    root@ccd4ad5f0ae4:/# ping -c 1 172.17.0.3
    PING 172.17.0.3 (172.17.0.3) 56(84) bytes of data.
    64 bytes from 172.17.0.3: icmp_seq=1 ttl=64 time=0.118 ms
    
    --- 172.17.0.3 ping statistics ---
    1 packets transmitted, 1 received, 0% packet loss, time 0ms
    rtt min/avg/max/mdev = 0.118/0.118/0.118/0.000 ms
    root@ccd4ad5f0ae4:/#
    

    I’ve searched the web up and down but didn’t find any hint to what I can look for. Both images are base don the ubuntu:1404 image and just install some packages via apt-get.

    I’ve also tried to use --dns option without luck.

    Any ideas I could have a look at?

    thx,

  • Running apache in an ubuntu Docker container on a RedHat machine
  • Cron job doesn't work until I re-save cron file in docker container
  • Docker compose wordpress plugins
  • Set machine name for docker-compose
  • docker-compose not setting environment variables
  • Akka Cluster with bind-port and bind-hostname
  • One Solution collect form web for “resolve internal DNS in linked docker containers”

    Find which DNS server you are using:

    nmcli dev list iface eth0 | grep IP4
    

    Then put the address to /etc/default/docker

    docker_OPTS="--dns 8.8.8.8"
    

    And restart docker

    sudo restart docker
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.