Docker Community Forums

Share and learn in the Docker community.

How to config the dns for a container

docker

(Simble1986) #1

I try to config a dns for a container with --dns

but after connect another network for this container, the dns config has been reset.

So, Is it possible to reconfig the dns of the container?


Steps:

create a container with --dns

# docker run -d -t --name t1 --dns="223.5.5.5" busybox
538b414aa29738752e8f8b6e5e9c2ce40347d9195a4f1389ea5d7d1dbbf5d9c0

get the resolv.conf

# docker exec 53 cat /etc/resolv.conf
nameserver 223.5.5.5

create a network

# docker network create testNet1 --subnet 111.0.0.0/24
1fb10ce7f43b1a330f8d0218851364b77c9a1db52b1ddf9fef0335ae11f5c0c1

connect the network to the container

# docker network connect testNet1 t1

show the resolv.conf again

# docker exec 53 cat /etc/resolv.conf
nameserver 127.0.0.11
options ndots:0

some informations

# docker -v
Docker version 18.03.1-ce, build 9ee9f40
# lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 16.04.4 LTS
Release:	16.04
Codename:	xenial
# uname -a
Linux slt-docker 4.4.0-128-generic #154-Ubuntu SMP Fri May 25 14:15:18 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux