apt-key fails recently inside docker

2.4k Views Asked by At

Lately, I'm getting this error when building Ubuntu/Debian based containers:

Warning: apt-key output should not be parsed (stdout is not a terminal)
Executing: /tmp/apt-key-gpghome.jZsMrv3GZH/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
mgpg: cannot open '/dev/tty': No such device or address

When I'm calling the apt-key commands such as these:

apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF

I could use apt with an untrusted option so I wouldn't need the key at all, but that sounds as a dirty solution.

When using gpg directly I probably could use the --no-tty or --batch options to fix it, but what is the somewhat clean way to do it with apt-key command which is a wrapper for the pgp?

1

There are 1 best solutions below

0
On

I think I got it, at least until the GPG or APT-KEY will be fixed I could use this workaround which does modify the apt-key script in place.

For the more fancier apt-key this will work, quickly tested on debian:

sed -i "s%{GPG_EXE}\")' --%{GPG_EXE}\")' --batch --%g" /usr/bin/apt-key

While for the basic apt-key this could work (untested as I can't recall exactly where I seen this simpler variant):

sed -i 's%GPG_CMD="gpg %GPG_CMD="gpg --batch %g' /usr/bin/apt-key

You need privileges to write to the the /usr/bin/apt-key so ither run as root or use sudo