Docker images lacking /tmp?

Viewed 2245

I was trying to build an image based on this one, which is based on Debian Stretch, and kept getting this kind of errors when running apt-get update:

W: GPG error: http://security.debian.org stretch/updates InRelease: Couldn't create temporary file /tmp/apt.conf.FNG6R8 for passing config to apt-key

This was fixed after just adding

mkdir /tmp && chmod 777 /tmp \

to the Dockerfile RUN. But then the question is, do Docker images lack the tmp file? Is that the case only for images based on buildpack-deps:stretch-scm? Is there a better way to deal with this than creating by hand a /tmp directory?

2 Answers

I had the same error as you and as BMitch suggested, adding this layer in my Dockerfile fixed it for me.

RUN chmod 1777 /tmp

/tmp exists inside the image, your issue is elsewhere:

$ docker run -it --rm buildpack-deps:stretch-scm /bin/bash
root@c7fc40670734:/# ls -al /tmp
total 8
drwxrwxrwt 1 root root 4096 Nov 16 11:16 .
drwxr-xr-x 1 root root 4096 Dec 27 19:48 ..

Note that /tmp should be set to 1777, not 777, you need the sticky bit for security

Related