How to change permissions to /tmp folder in Docker image

Hi! In my Dockerfile, I have this line:

RUN chmod go-w -R /tmp && mkdir /tmp/secrets

it builds successfully. On my local machine, this works. There is a folder under /tmp and the folder itself has the right permissions.

However, in my image on Digital Ocean Apps; /tmp is still marked with drwxrwxrwt root root and there is no directory /tmp/secrets

Why is it like this?

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there,

I believe that /tmp is cleared after every restart meaning that once you start a container from that image, it will have a blank /tmp directory.

Alternatively, you could use /var/tmp as it does not get cleared after a restart.

I’ve just tested this with /var/tmp and it seems to be working as expected.