Fixing "The following signatures couldn't be verified because the public key is not available: NO_PUBKEY: %s" error

I was recently trying to build an old Docker container for one of our projects and I faced this error:

#7 10.88 W: GPG error: http://apt.datad0g.com stable Release: The following signatures couldn't
be verified because the public key is not available: NO_PUBKEY {{key}}
#7 10.88 E: The repository 'http://apt.datad0g.com stable Release' is not signed.

In case you were wondering what is going on like I did, it appers that the apt packaging system has a set of trusted keys that determine whether a package can be authenticated and therefore trusted to be installed on the system. Sometimes the system does not have all the keys it needs and runs into this issue.

Luckily this can be easily fixed by adding

apt-key adv --keyserver keyserver.ubuntu.com --recv-keys {{key}}

run command to your Dockerfile.

Hope that will help me in the future as well :)

Happy coding.