Zenn
🐳

Docker Hubのレート制限対策をした ~Podman Desktop (Docker Compatibility)編~

2025/03/03に公開

もう気軽にdocker pullできない。Docker Hub未認証ユーザーだと。

2025年4月1日以降のDocker Hubのレート制限が厳しいので、とりあえず自分の開発PCでmirror.gcr.ioからイメージを取得するようにしておこうと思いました。

あくまで私のPC環境でしか試してないので、もしかしたら誰かの参考になるかも程度の記事です。

https://docs.docker.com/docker-hub/usage/

Starting April 1, 2025, all users with a Pro, Team, or Business subscription will have unlimited Docker Hub pulls with fair use. Unauthenticated users and users with a free Personal account have the following pull limits:

  • Unauthenticated users: 10 pulls/hour
  • Authenticated users with a free account: 100 pulls/hour

やること

podman-desktop.ioに記載の手順に従ってregistries.confの設定を行ない、実際にdocker pullをしてmirror.gcr.ioから取得していることを確認します。
https://podman-desktop.io/docs/containers/registries#setting-up-a-registry-with-an-insecure-certificate

私のPC環境

MacBook Pro (14インチ, 2023)
Podman Desktop v1.16.2
Podman v5.3.2

トライ

1. まずはそのまま、docker pullをしてみます。

今回はhello-worldのイメージをpullします。

docker image pull hello-world

この時、tcpdumpコマンドでregistry-1.docker.io宛のパケットを確認してみます。
私の環境ではネットワークインターフェースen9が使われていたため、tcpdumpのiオプションにen9を指定してますが、実際試す際には各自でifconfigなどでネットワークインターフェースを調べましょう。

sudo tcpdump \
  -nni en9 \
  host \($(dig registry-1.docker.io +short | xargs printf "%s or " | sed 's/ or $//')\)

実行結果

下記のように、docker image pullの実行によってregistry-1.docker.ioへの通信が発生していることが分かりました。(当たり前)

キャプチャ
(左) docker image pullを実行
(右) tcpdumpでregistry-1.docker.io宛のパケットキャプチャを実行

2. podman-machineにsshで接続し、registries.confに設定を追加します。

podman machine ssh --username root
cat << EOF >> /etc/containers/registries.conf
[[registry]]
location = "docker.io"

[[registry.mirror]]
location = "mirror.gcr.io"
insecure = true
EOF

3. podman-machineを再起動します。

podman machine stop && podman machine start

4. 再度docker pullを試してみます。

イメージを一回削除してから、pullします。

docker image rm hello-world
docker image pull hello-world

この時、再度のtcpdumpコマンドでregistry-1.docker.iomirror.gcr.io宛のパケットをそれぞれ確認してみます。

sudo tcpdump \
  -nni en9 \
  host \($(dig registry-1.docker.io +short | xargs printf "%s or " | sed 's/ or $//')\)
sudo tcpdump \
  -nni en9 \
  host \($(dig mirror.gcr.io +short | xargs printf "%s or " | sed 's/ or $//')\)

実行結果

期待通り、registry-1.docker.ioへの通信は無くなり、mirror.gcr.ioからイメージが取得されていることが分かります。


(左) docker image pullを実行
(右上) tcpdumpでregistry-1.docker.io宛のパケットキャプチャを実行
(右下) tcpdumpでmirror.gcr.io宛のパケットキャプチャを実行

おわりに

しばらくこの状態で開発作業をやってみます。

ちなみに、tcpdumpの件はこちらのサイトを参照させてもらいました。

https://blog.monophile.net/posts/20201101_docker_mirror_gcr_io.html

すごい偶然だったのですが、こちらのサイト管理者の方、私と出身校が同じで2歳上の方だったので、もしかしたらどこかですれ違ったことあるかもしれないです。

レバテック開発部

Discussion

ログインするとコメントできます