The following command seems to work when running it in a shell
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
but fails when executed in a Dockerfile
as follows:
Warning: apt-key output should not be parsed (stdout is not a terminal)
Executing: /tmp/apt-key-gpghome.1CIuj3LUOP/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
gpg: cannot open '/dev/tty': No such device or address
The specific Dockerfile
RUN commands executes on a openjdk:8
image which in turn draws from buildpack-deps:stretch-scm
Key takeaways: Set DEBIAN_FRONTEND=noninteractive to prevent some packages from prompting interactive input ( tzdata for example), which leads to indefinite waiting for an user input. Run apt update before the install command to fetch the current package lists.
You can't run Docker commands from a Dockerfile (and shouldn't as a general rule try to run Docker commands from within Docker containers) but you can write an ordinary shell script on the host that runs the docker build && docker run .
Looking at the docker best pratices, you should do update but not upgrade as this require your container to run with privileged permission. Doing the update make sure you are installing the latest version of the package you want to install.
Docker Dockerfiles SHELL Instruction The SHELL instruction allows the default shell used for the shell form of commands to be overridden. The default shell on Linux is ["/bin/sh", "-c"] , and on Windows is ["cmd", "/S", "/C"] . The SHELL instruction must be written in JSON form in a Dockerfile.
Solved by adding --no-tty
on the apt-key adv
command also;
Any idea however why this was happening?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With