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 docker.io
$ sudo ln -sf /usr/bin/docker.io /usr/local/bin/docker
$ sudo sed -i '$acomplete -F _docker docker' /etc/bash_completion.d/docker.io

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 (8.8.8.8 and 8.8.4.4). 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=192.168.2.1 -i -t ubuntu /bin/bash

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

$ sudo nano /etc/default/docker.io

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

$ sudo restart docker.io

(192.168.2.1, 192.168.3.1 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: https://docs.docker.com/articles/networking/ and http://docs.docker.com/installation/ubuntulinux/#ubuntu-trusty-1404-lts-64-bit

Comments