Search code examples
dockernginxdocker-composeconfigurationdns

nslookup returns communications error to 127.0.0.53#53: timed out; no servers could be reached


I am following a tutorial on YouTube about Nginx and as I follow him, I received an error from the dns container. At first I can run docker-compose build but docker-compose up fails because of systemd-resolved is using port 53. I was able to fix using instructions from this link. listen tcp 0.0.0.0:53: bind: address already in use #65

Now, when I run docker-compose up and it didn't fail but when I test it using command nslookup, I received an error like no servers could be reached. (FYI: I am using Ubuntu 22.04 on my machine).

;; communications error to 127.0.0.53#53: timed out ;; communications error to 127.0.0.53#53: timed out ;; communications error to 127.0.0.53#53: timed out ;; no servers could be reached

dns/zone/main.com

$ttl 86400
@       IN      SOA ns.main.com.    hostmaster.main.com.(
                    202 ; Serial
                    600 ; Refresh
                    3600 ; Retry
                    12378237) ; Expire

@       IN      NS  ns.main.com.
ns      IN      A   127.0.0.1

dns/Dockerfile

FROM alpine:latest
RUN apk add bind openrc
RUN rc-update -u named

dns/named.conf

options {
    directory "var/bind";
    allow-transfer { "none"; };
    allow-query { any; };
    listen-on { any; };
};

zone "main.com" IN {
    type master;
    file "/etc/bind/zone/main.com";
};

nginx/conf.d/default.conf

server {
    listen 80;
    server_name ns.main.com;

    location / {
        root /usr/share/nginx/html/main;
        index index.html;
    }
}

nginx/Dockerfile

FROM nginx:latest
COPY ./html /usr/share/nginx/html
RUN apt-get update && apt-get install -y procps

docker-compose.yml

services:
  nginx:
    build:
      context: ./nginx/
    ports:
      - 80:80
    volumes:
      - ./nginx/html/:/usr/share/nginx/html/
      - ./nginx/conf.d/:/etc/nginx/conf.d/
  dns:
    build:
      context: ./dns/
    restart: always
    ports:
      - 53:53
      - 53:53/udp
    volumes:
      - ./dns/named.conf:/etc/bind/named.conf
      - ./dns/zone/:/etc/bind/zone/
    command: named -c /etc/bind/named.conf -g -u named

Hope you can enlighten me. Looking forward to improve. Thanks!


Solution

  • Let's try some things

    Try 1

    Remove one of the line (by setting twice port 53, you confirm that port 53 is use)

        ports:
          - 53:53
          - 53:53/udp // delete line
    

    Try 2

    services:
      nginx:
        build:
          context: ./nginx/
        ports:
          - 80:80
        volumes:
          - ./nginx/html/:/usr/share/nginx/html/
          - ./nginx/conf.d/:/etc/nginx/conf.d/
      dns:
        build:
          context: ./dns/
        restart: always
        ports:
          - <ANOTHER_PORT>:53 // change <ANOTHER_PORT> with an available port
        volumes:
          - ./dns/named.conf:/etc/bind/named.conf
          - ./dns/zone/:/etc/bind/zone/
        command: named -c /etc/bind/named.conf -g -u named