🎃
docker image のビルドに失敗する (Temporary failure resolving ...)
Ubuntu 22.04.2 LTS Server において docker image のビルドに失敗したので対策方法のメモ
結論
docker build --network host
のように --network host
オプションをつける。
こんな感じ
docker build --network host -t docker-test:1 ./docker-conf
対策をしないときのエラーメッセージ
$ docker build -t ....
略
---> Running in 709bc69a12ae
Err:1 http://archive.ubuntu.com/ubuntu bionic InRelease
Temporary failure resolving 'archive.ubuntu.com'
Err:2 http://security.ubuntu.com/ubuntu bionic-security InRelease
Temporary failure resolving 'security.ubuntu.com'
Err:3 http://archive.ubuntu.com/ubuntu bionic-updates InRelease
Temporary failure resolving 'archive.ubuntu.com'
Err:4 http://archive.ubuntu.com/ubuntu bionic-backports InRelease
Temporary failure resolving 'archive.ubuntu.com'
Reading package lists...
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/bionic/InRelease Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/bionic-updates/InRelease Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/bionic-backports/InRelease Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/bionic-security/InRelease Temporary failure resolving 'security.ubuntu.com'
W: Some index files failed to download. They have been ignored, or old ones used instead.
略
説明
ホストの DNS 設定 設定確認
$ cat /etc/resolv.conf
省略
nameserver 127.0.0.53
options edns0 trust-ad
search .
/etc/resolv.conf
の書き換え うまくいかない方法
nameserver 8.8.8.8
のように DNS をローカルマシンではなく、外部の DNS サーバーに書き換えてみた。
→ /etc/resolv.conf
がいつの間にか書き戻される。
docker build
に --network host
を指定する。 うまくいく方法
docker build
には --dns
オプションがないので --network host
を指定して
ホストネットワークを使う。
参考
- https://kazuhira-r.hatenablog.com/entry/2020/04/12/194225 (これがうまくいった)
-
https://rabbitfoot141.hatenablog.com/entry/2018/11/22/191858 (これでは動かなかった。
/etc/resolv.conf
が書き戻される。) - https://docs.docker.jp/network/host.html
Discussion