LoginSignup
27
11

More than 1 year has passed since last update.

MacOS×Rancher Desktopでdocker image pullが使えないの解決法

Last updated at Posted at 2022-03-06

0.動作環境

・MacBook Pro(13-inch, 2019, Intel i5) おそらくM1でも可能だけど検証はしてない
・MacOS Monterey:12.2.1
・docker: 20.10.9
・Rancher Desktop: 1.1.0(Kubernetes versionv1.22.7 dockerd)

1.事前準備

まずDocker Desktopの環境が残っている方は、以下の記事を参考に削除 、RancherDesktopインストール

Docker DesktopからRancher Desktopに乗り換えてみた - knqyf263's blog

2.解決すること

$ docker run hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get "[https://registry-1.docker.io/v2/](https://registry-1.docker.io/v2/)": dial tcp: lookup [registry-1.docker.io](http://registry-1.docker.io/) on 192.168.5.3:53: read udp 192.168.5.15:40523->192.168.5.3:53: i/o timeout.
See 'docker run --help'.

2.結論

Docker network issues when using Rancher Desktop on Mac with Apple Silicon ARM-based processor (M1 chip)

参考に、魔法のスクリプトを走らせる

$ /bin/bash -c "$(curl -fsSL https://gist.githubusercontent.com/mackankowski/be575ec0b81fd8ba3a948d3e84410adc/raw/979b09ab2cc6225ddee1aedaf9e893bb839a715a/script.sh)"

もし、limaが存在しないと言われたら、一つずつ実行

$ LIMA_HOME="$HOME/Library/Application Support/rancher-desktop/lima" "/Applications/Rancher Desktop.app/Contents/Resources/resources/darwin/lima/bin/limactl" shell 0

$ sudo chown $(whoami) /etc/resolv.conf

$ sudo sed -i 's/nameserver.*/nameserver 8.8.8.8/g' /etc/resolv.conf

自分はこれで幸せになれた。

3.ちょっと経緯を詳しく

いろんなサイトや記事で「Rancher desktopすげぇ!!」「Docker Desktopの代わりはお前しかいねぇ」みたいな感じでもてはやされてたので試して見た。

インストールまで問題なくでき、dockerコマンドも叩けて、「おおっ」となり、

$ docker run hello-world

したところで

Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get "[https://registry-1.docker.io/v2/](https://registry-1.docker.io/v2/)": dial tcp: lookup [registry-1.docker.io](http://registry-1.docker.io/) on 192.168.5.3:53: read udp 192.168.5.15:40523->192.168.5.3:53: i/o timeout.
See 'docker run --help'.

これにそこそこはまった。

どうやらdockerイメージをレジストリからとって来る際にDNSの名前解決がうまくいっていないということらしいのだが、なぜうまくいかないのか...

一応対策としてWSL2環境で、以下のようにGoogleが提供しているパブリックDNS8.8.8.8を自分のDNSサーバーに設定して対処しているケースがあったので、自分も同じようにしてみたけどダメだった。

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

それもそのはずで、どうやらそもそもMacのDNSはシステム環境設定>ネットワーク環境から変更するもので、/etc/resolv.confにはその設定値が書いてあるに過ぎなかったらしい。なるほど、と思い変更し再度実行。うまくいかず。
ここで、本当はエンジニアたるもの一番最初にエラー解決の手段として上がらなければいけないことを実行する決意をした。

「GitHubのissue見るか...」

実際あった。早く見とけばよかった。

https://github.com/rancher-sandbox/rancher-desktop/issues/1633

そもそもRancher DesktopがDocker Desktop のように中でLinuxVM(lima)を動かしていることを理解していれば、中のLinuxマシンのシェルに入ってDNSサーバーの値を変えなければいけないのはわかったはず...
そして、、、

$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:97a379f4f88575512824f3b352bc03cd75e239179eea0fecc38e597b2209f49a
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

4.おまけ

簡単にRancher Desktop導入手順

brew install --cask rancher #gui内でシンボリックにチェック
#dockerコマンドとkubectlコマンドなければ
brew install docker
brew install kubectl
あと上記対応。

5.最後に

普段自分が使うサービスがどう動いているのか、確認しなきゃなっていうのと、「困ったらissue」は鉄則だなと思った。
何か適当なこと言ってたら、ご教授いただけると幸甚です。

6.参考にした記事

コラム - きほんの トラブルシューティング | 第1回 サイトにアクセスできないときは、パブリックDNS 8.8.8.8 を設定してみよう|CTC教育サービス 研修/トレーニング

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

MacのDNSを設定 - ぷろぐらまはっくす MkⅡ

27
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
27
11