How to change the dns of a running docker container

the default dns 8.8.8.8 and 8.8.4.4 are blocked by my nation’s firewall, and I do not want to stop the container for I install a lot of software in it.

  • Docker images on different docker versions
  • How to create an automated build after the DockerHub redesign?
  • Hyperledger Docker endpoint not found
  • org.jolokia:docker-maven-plugin:0.10.4:push (code: 500, Internal Server Error)
  • Why docker start is much faster than docker run
  • Accessing microservice inside Docker container?
  • How to limit Docker filesystem space available to container(s)
  • dockerize c#.NET desktop application
  • Docker build command output unavailable
  • Php on docker : Using setLocale
  • Linking containers with Mesos JSON file
  • using docker for quick switching iojs version
  • One Solution collect form web for “How to change the dns of a running docker container”

    If you want to change the DNS, you can just do it in the same way you would on a normal host and this should just work. For example editing the /etc/resolv.conf file in the container.

    Although if it is entirely blocked, I’d recommend a more permanent solution.

    In /etc/default/docker (may be /etc/default/docker.io on Debian based hosts) you can add a line to set the default DNS on new containers. This line would look something like

    DOCKER_OPTS="-dns 8.8.8.8 -dns 8.8.4.4"
    

    You can just add a new -dns x.x.x.x for every DNS server you wish to use to resolve.

    Once you have done this you will need to restart the Docker process. This is done in a few ways depending on the host again. For Debian based hosts:

     service docker.io restart
    

    When you docker run a new container, it will have those DNS servers set.

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