Search code examples
dockerubuntudns

Docker apt-get update fails


Can somebody help me get apt-get working in my docker container? Whenever I try running any apt-get command in my docker container, the command fails. I'm running Docker version 1.1.1, build bd609d2 on ubuntu 12.04.

When I do

$ sudo docker run -i -t ubuntu:14.04 /bin/bash
# apt-get update

I get errors saying

Could not resolve 'archive.ubuntu.com'

I tried uncommenting the line below in /etc/default/docker

DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4"

but I still can't ping google.com

ping: unknown host

I confirmed that the container is using the dns servers 8.8.8.8 and 8.8.4.4

root@0baa87fc6322:/# cat /etc/resolv.conf

nameserver 8.8.8.8

nameserver 8.8.4.4

and I'm able to ping both servers so I'm pretty sure that a firewall isn't just dropping my packets.

Any help with this would be appreciated!

Thanks!


Solution

  • Thanks for all your help! I found out it was a dns problem and that it was because of a firewall. After searching some more I found this question that I wasn't able to find while searching 'docker apt-get fail'

    Docker - Network calls fail during image build on corporate network

    His problem was similar to mine and the solution helped me get it working. I've copied over his solution for anybody that finds this question in the future.

    Those Google servers weren't accessible from behind our firewall, which is why we couldn't resolve any URLs.

    The fix is to tell Docker which DNS servers to use. This fix depends on how you installed Docker: Ubuntu Package

    If you have the Ubuntu package installed, edit /etc/default/docker and add the following line:

    DOCKER_OPTS="--dns <your_dns_server_1> --dns <your_dns_server_2>"

    You can add as many DNS servers as you want to this config. Once you've edited this file you'll want to restart your Docker service:

    sudo service docker restart

    Binaries

    If you've installed Docker via the binaries method (i.e. no package), then you set the DNS servers when you start the Docker daemon:

    sudo docker -d -D --dns --dns &