Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

apt cannot verify the Docker repository: public key is not available

ErrorThe following signatures couldn't be verified because the public key is not available: NO_PUBKEY

Short answer

apt checks every repository against a signing key. NO_PUBKEY means the Docker key is missing, unreadable, in a format this apt cannot use, or the Signed-By path in the source file points to nothing. Re-create the keyring and sources file the way Docker's install guide shows, then run apt update.

  • Applies to Ubuntu 24.04, Docker Engine 28
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Look at the source file for Docker and check that the key file it names exists.

    cat /etc/apt/sources.list.d/docker.sources
    ls -l /etc/apt/keyrings/
  2. 2Match what you see, then jump to its fix

    1. 1NO_PUBKEY on download.docker.com right after adding the repositoryThe key was never downloaded, or the file is not where Signed-By saysFix
    2. 2NO_PUBKEY persists although the key file existsThe sources file is incomplete or was written by hand with a typoFix
    3. 3NO_PUBKEY on an old Ubuntu or Debian although the key file is presentThe key is ASCII-armored and this apt is too old to read itFix

What does the error look like?

  • The following signatures couldn't be verified because the public key is not available: NO_PUBKEY

Cause 1 of 3

The key was never downloaded, or the file is not where Signed-By says

1Check

The Signed-By line must point to a real file, not a fingerprint. Compare the path in the source file with the keyring folder.

grep -n "Signed-By" /etc/apt/sources.list.d/docker.sources
ls -l /etc/apt/keyrings/docker.asc

2Fix

Download the key to the path the source file uses, as Docker's guide shows, and make it readable.

sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

3Verify

apt update runs with no signature error for the Docker repository.

sudo apt update

Confirmed by docs.docker.com

Did this fix it?

Cause 2 of 3

The sources file is incomplete or was written by hand with a typo

1Check

Compare your file to the documented one: Types, URIs, Suites, Components, Architectures and Signed-By.

cat /etc/apt/sources.list.d/docker.sources

2Fix

Rewrite the file with the documented content. The suite is read from the OS release.

sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Architectures: $(dpkg --print-architecture)
Signed-By: /etc/apt/keyrings/docker.asc
EOF
sudo apt update

3Verify

apt update lists download.docker.com without errors.

apt-cache policy docker-ce

Confirmed by docs.docker.com

Did this fix it?

Cause 3 of 3

The key is ASCII-armored and this apt is too old to read it

1Check

Debian's guidance: armored key files only work with apt 1.4 or later. Check your apt version.

apt --version

2Fix

Convert the key to the binary format with gpg --dearmor, save it as a .gpg file, and point Signed-By at that file.

sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg /etc/apt/keyrings/docker.asc
# then set: Signed-By: /etc/apt/keyrings/docker.gpg

3Verify

apt update completes with no signature error.

sudo apt update

Confirmed by wiki.debian.org

Did this fix it?

How do I stop it coming back?

  • Follow the vendor's current install page instead of old copy-pasted apt-key add commands.
  • Keep third-party keys in /etc/apt/keyrings and reference them with Signed-By.
  • Do not load third-party keys with apt-key add or put them in trusted.gpg.d.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Servers

A dev container port does not open in the browser when Docker runs on a remote host

If your application only accepts calls from localhost, it will reject connections from published ports

Three things usually break it: the app listens only on localhost inside the container, so published ports are rejected; you open the container port instead of the mapped localhost port VS Code shows; or you changed appPort or a Compose ports list and did not rebuild.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.