Mekal Z

Mekal Z

A programmer running out of the wall.
twitter

Recording a Docker Build DNS resolution issue

When I executed the following command to build a Docker image in my local Ubuntu system, I encountered a DNS resolution issue. I used GoProxy to specify the Alibaba Cloud proxy in the Dockerfile, but the DNS resolution failed during the build process.

sudo docker compose -f ./compose-dev.yaml build

[+] Building 2.0s (9/14)
 => [internal] load .dockerignore                                                                                                                                                                                                                                                                                                                                      0.0s
 => => transferring context: 2B                                                                                                                                                                                                                                                                                                                                        0.0s
 => [internal] load build definition from Dockerfile                                                                                                                                                                                                                                                                                                                   0.0s
 => => transferring dockerfile: 1.27kB                                                                                                                                                                                                                                                                                                                                 0.0s
 => [internal] load metadata for docker.io/library/golang:1.20-buster                                                                                                                                                                                                                                                                                                  1.5s
 => [builder 1/7] FROM docker.io/library/golang:1.20-buster@sha256:73c225bc5e2353f20dbe0466819b70a51a114a93bfe4af035a3bb9e1ecdd4107                                                                                                                                                                                                                                    0.0s
 => [internal] load build context                                                                                                                                                                                                                                                                                                                                      0.0s
 => => transferring context: 812.84kB                                                                                                                                                                                                                                                                                                                                  0.0s
 => CACHED [builder 2/7] RUN mkdir -p /app                                                                                                                                                                                                                                                                                                                             0.0s
 => CACHED [builder 3/7] WORKDIR /app                                                                                                                                                                                                                                                                                                                                  0.0s
 => [builder 4/7] COPY . /app                                                                                                                                                                                                                                                                                                                                          0.0s
 => ERROR [builder 5/7] RUN go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct     && go get -d -v ./...                                                                                                                                                                                                                                                     0.3s
------
 > [builder 5/7] RUN go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct     && go get -d -v ./...:
#0 0.313 go: github.com/BurntSushi/toml@v0.3.1: Get "https://mirrors.aliyun.com/goproxy/github.com/%21burnt%21sushi/toml/@v/v0.3.1.mod": dial tcp: lookup mirrors.aliyun.com on [240e:d:0:100::6]:53: dial udp [240e:d:0:100::6]:53: connect: cannot assign requested address
------
failed to solve: process "/bin/sh -c go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct     && go get -d -v ./..." did not complete successfully: exit code: 1

The solution is to set the DNS in /etc/docker/daemon.json, for example:

{
    "dns": ["8.8.8.8", "8.8.4.4"],
    "log-driver": "json-file",
    "log-opts": {
        "max-size": "50m",
        "max-file": "3"
    }
}
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.