WSL2 環境で docker pull に失敗した時の対処方法

WSL2 環境で docer pull したところタイムアウトが発生し、イメージを取得できなかったときの対処方法をメモしておく。

エラー内容

docker pull コマンドを実行したところ、下記のエラーが発生しイメージを取得できなかった。

1
2
3
$ sudo docker pull redis
Using default tag: latest
Error response from daemon: Get https://registry-1.docker.io/v2/: dial tcp: lookup registry-1.docker.io on 172.23.64.1:53: read udp 172.23.73.2:42560->172.23.64.1:53: i/o timeout

対策方法

エラーメッセージを見てみると、TCP の 53 番ポートに問題があるように見える。53 番といえば DNS なので、/etc/resolve.conf の nameserver 設定を 8.8.8.8 に変更してみた。

1
2
3
4
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 8.8.8.8

再度、Docker イメージの取得を試みる。

1
2
3
4
5
6
7
8
9
10
11
$ sudo docker pull redis
Using default tag: latest
latest: Pulling from library/redis
d121f8d1c412: Pull complete
2f9874741855: Pull complete
d92da09ebfd4: Pull complete
bdfa64b72752: Pull complete
e748e6f663b9: Pull complete
eb1c8b66e2a1: Pull complete
Digest: sha256:1cfb205a988a9dae5f025c57b92e9643ec0e7ccff6e66bc639d8a5f95bba928c
Status: Downloaded newer image for redis:latest

無事、取得に成功した。