The host can access the public network but cannot be accessed in the Docker container. Temporary failure in name resolution

The host can access the public network but cannot be accessed in the Docker container. Temporary failure in name resolution


Container parameters 

I have also set up the dns of docker-compose.yml. Logically speaking, it should be accessible, but it just keeps rubbing on the ground.

  web:
    build: .
    restart: always
    ports:
      - "6699:80"
    dns:
      - 114.114.114.114
      - 8.8.8.8
    volumes:
      - "./:/app"
    networks:
      backend:

troubleshooting

Whether the container can be accessed using the public IP address, I can access it here, but cannot access it using the domain name. When accessing the domain name via telnet, it prompts Temporary failure in name resolution, which means that the domain name cannot be resolved. The problem must be in DNS, so here comes the question. Inspiration: Isn’t it enough to keep the DNS of the container consistent with that of the host? As a result, I will try the following method to verify the correctness of my guess.

Solution

Check the host’s dns service

 cat /etc/resolv.conf

 Then add the host's nameserver to the container

  web:
    build: .
    restart: always
    ports:
      - "6699:80"
    dns:
      - 183.xx.xx.19 // 把宿主机的域名服务添加在这里
      - 183.xx.xx.98 // 把宿主机的域名服务添加在这里
      - 114.114.114.114
      - 8.8.8.8
    volumes:
      - "./:/app"
    networks:
      backend:

Then save, run docker-compose up -d --build to update the container configuration, and you're done.

Guess you like

Origin blog.csdn.net/meimeieee/article/details/131521090