Docker Build with /dev/shm exec

Viewed 548

I'm trying to build a docker image and the building process requires the /dev/shm to have exec but by default /dev/shm is mounted with noexec. I know I can do a docker run --tmpfs /dev/shm:rw,exec imagename and then everything works but there seems to be no equivalent in docker build.

1 Answers

This may be a bit late, but for anyone else who ends up here, there's a flag you can use in dockerfiles for BuildKit that lets you do file system mounts at build time. By changing your dockerfile's RUN line to include a mount flag, you can overwrite the builders usual shared memory directory with a new temporary file system that has the right permissions. I've found that the following works:

RUN --mount=type=tmpfs,target=/dev/shm,rw \
    yourDatabaseImportScript.sh

This will require the machine you're using to build the image has BuildKit enabled

BuildKit mounts flag documentation
Setting permissions on BuildKit tmpfs mounts
Oracle's FAQ answer on permissions needed for /dev/shm

Related