Mekal Z

Mekal Z

A programmer running out of the wall.
twitter

記錄一個 Docker Build DNS 解析問題

我在本地 Ubuntu 系統內執行如下命令 Build 一個 Docker 鏡像的時候,出現了一個 DNS 解析的問題。我是在 Dockerfile 中使用 GoProxy 指定了阿里雲的代理,但是在 Build 的時候無法解析 DNS。

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

解決方法就是在 /etc/docker/daemon.json 設置好 DNS,例如:

{
    "dns": ["8.8.8.8", "8.8.4.4"],
    "log-driver": "json-file",
    "log-opts": {
        "max-size": "50m",
        "max-file": "3"
    }
}
載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。