ubuntu 環境にて Docker をインストールしようとする際 “sudo apt-get update” を実行する必要があると思いますが、実行した際にエラーが発生してうまくいかなかったということがあると思います。
その際の対処法としていくつか方法がございますので、それらをご紹介いたします。
私自身これに結構な時間を取られてしまったので、同じような局面に遭遇してしまった人へ手助けになれば幸いです。
恐らく、 Docker をインストールしようとした際にのみ起きる事象かと思いますが、もしかしたらそのほかの場面で “sudo apt-get update” をしようとしたときに同じようなエラーが出ていれば役に立つかもしれません。
目次
事象について
ubuntu 環境で Docker をインストールしようとすると恐らく以下の公式サイトに辿り着くと思います
Docker Engine インストール(Ubuntu 向け)
上記の手順、「Docker Engine のインストール」を実施する際に “sudo apt-get update” を実行する必要があると思いますがこれを実施した際に以下のようなエラーが出てしまう場合があります。
Get:1 https://download.docker.com/linux/ubuntu jammy InRelease [48.9 kB]
Err:1 https://download.docker.com/linux/ubuntu jammy InRelease
The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY 7EA0A9C3F273FCD8
Hit:2 http://security.ubuntu.com/ubuntu jammy-security InRelease
Hit:3 http://archive.ubuntu.com/ubuntu jammy InRelease
Hit:4 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Hit:5 http://archive.ubuntu.com/ubuntu jammy-backports InRelease
Reading package lists… Done
W: GPG error: https://download.docker.com/linux/ubuntu jammy InRelease: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY 7EA0A9C3F273FCD8
E: The repository ‘https://download.docker.com/linux/ubuntu jammy InRelease’ is not signed.
N: Updating from such a repository can’t be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: Target Packages (stable/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list.d/archive_uri-https_download_docker_com_linux_ubuntu-jammy.list:1 and /etc/apt/sources.list.d/docker.list:1
W: Target Packages (stable/binary-all/Packages) is configured multiple times in /etc/apt/sources.list.d/archive_uri-https_download_docker_com_linux_ubuntu-jammy.list:1 and /etc/apt/sources.list.d/docker.list:1
W: Target Translations (stable/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list.d/archive_uri-https_download_docker_com_linux_ubuntu-jammy.list:1 and /etc/apt/sources.list.d/docker.list:1
W: Target CNF (stable/cnf/Commands-amd64) is configured multiple times in /etc/apt/sources.list.d/archive_uri-https_download_docker_com_linux_ubuntu-jammy.list:1 and /etc/apt/sources.list.d/docker.list:1
W: Target CNF (stable/cnf/Commands-all) is configured multiple times in /etc/apt/sources.list.d/archive_uri-https_download_docker_com_linux_ubuntu-jammy.list:1 and /etc/apt/sources.list.d/docker.list:1
このログの重要なポイントは「NO_PUBKEY 7EA0A9C3F273FCD8」という記述ですね。
要は公開鍵がありませんけど?とおっしゃってます。
なのでそれに対処するような手順を実施する必要があります。
なお、公式サイトの手順には今から紹介する手順を実施する必要があるそうで、ほぼ高確率でこのエラーに直面すると思います。。。
対処法
それでは対処法をご紹介いたします。
幾つか対処する方法があるので、有用な順に紹介していきます。
1. GPGキーを取得してアクセス許可を付与する。
GPGキーが足りないことにエラーが発生している場合があるので、そのためのキーを追加し、それにアクセスできるようにします。
まずは以下のコマンドでGPGキーを取得します。
sudo mkdir -p /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg –dearmor –yes -o /etc/apt/keyrings/docker.gpg
次にアクセス許可を付与します。
sudo chmod a+r /etc/apt/keyrings/docker.gpg
以上が完了したら “apt-get update” を実行してください。
2.デフォルト Docker キーの権限を修正
一部のデフォルト Docker キーが誤った権限でインストールされた可能性があった場合にもこのエラーが起きるので正しい権限に直してあげます。
これは以下のコマンドを実施するだけです。
sudo chmod a+r /usr/share/keyrings/docker-archive-keyring.gpg
以上が完了したら “apt-get update” を実行してください。
3. 追加した鍵にリポジトリに接続できるように設定する
公式の手順にも鍵を追加するステップがありますが、実はそれだけでは足りなくて以下に記載するコマンドを実施する必要があるようです。
私はこの手順で治りましたのでもしかしたら一番これが有用かもしれません。
まず公式の以下の手順まで実施します。
>2. Docker の公式 GPG 鍵を追加します。
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg –dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
これを実施した後に以下の手順を実行します。
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg –dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
以上が完了したら “apt-get update” を実行してください。
以上3つの手順を紹介しました。
キーの追加と権限の付与ですが、3つの手順をやってもうまくいかない場合は最期にまた以下のコマンドで再度付与するとうまくいったりするのでそれらも試してみてください。
sudo chmod a+r /usr/share/keyrings/docker-archive-keyring.gpg
いかがでしょうか。
この問題であれば基本的に上記の内容で解決できると思います。
もし解決しなかったとしても同じような解決方法で解決できるような手順となると思います。
上記の手順で解決しなければご連絡いただけますと幸いです。
コメント