Monday, September 15, 2014

Docker - DNS setting in a default Ubuntu docker image

I just tried to create a container for my django apps this morning with docker. These were steps that I's following:

$ sudo apt-get update
$ sudo apt-get install
$ sudo ln -sf /usr/bin/ /usr/local/bin/docker
$ sudo sed -i '$acomplete -F _docker docker' /etc/bash_completion.d/

Then I pulled the ubuntu images to my docker environemt:

$ sudo docker pull ubuntu

Execute the bash shell of the ubuntu image:

$ sudo docker run -i -t ubuntu /bin/bash

But, I could not install any package (e.g. python2.7). I could not connect to the Internet. I checked the DNS settings on the container and found that It's configured with Google's DNS servers by default which is forbidden in my company's network ( and But, the thing is I could not even change the DNS configuration on that Ubuntu image. So, I go back to the docker's documentation and found a way to indicate the dns server when running the image:

$ sudo docker run --dns= -i -t ubuntu /bin/bash

or if you want to set the default DNS name servers, edit the docker configuration:

$ sudo nano /etc/default/

# Add:
DOCKER_OPTS="--dns --dns"

$ sudo restart

(, are my company's DNS servers)

Now I can install any packages and update the container.

For more information about networking in docker, please read: and