Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

apt-key command works on shell but fails on Dockerfile

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

like image 806
pkaramol Avatar asked Nov 19 '18 09:11

pkaramol


People also ask

Can I use apt get in Dockerfile?

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.

Can you run docker commands in Dockerfile?

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 .

Should I apt get update in Dockerfile?

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.

What is shell command in Dockerfile?

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.


Video Answer


1 Answers

Solved by adding --no-tty on the apt-key adv command also;

Any idea however why this was happening?

like image 77
pkaramol Avatar answered Oct 18 '22 05:10

pkaramol