Docker DNS issue on CentOS7


DNS name resolution doesn’t work in Docker containers

The case of the following production server environment.

  • CentOS7
  • Docker

DNS name resolution doesn’t work, when it access a endpoint outside docker container. One of the following two ways that sets up dns on docker container resolves the issue.

Set up dns in “docker-compose.yml" directly

update docker-compose.yml with the following.

version: '3.3'
      restart: always

Mounting resolv.conf file to container

You create the following resolv.conf file, then you mount the flie at /etc/resolv.conf inside the container.

search google.internal
options ndots:0

DNS resolution doesn’t work in Docker after reboot CentOS

Despite taking the above two ways, sometimes DNS doesn’t resolve in Docker after reboot server.

It is necessary running the docker.service after service. The following is the default [Unit] in docker.service.

Description=Docker Application Container Engine
BindsTo=containerd.service firewalld.service containerd.service

But sometimes docker.service begin to run before the network setting on is completed. I found the solution that include the following in the [Service].

ExecStartPre=/bin/sleep 5

This is unreasonable way waiting 5s. But it work correctry.