I have this in my Dockerfile:
FROM mcr.microsoft.com/mssql/server:latest
RUN mkdir -p /new-folder
Since the latests release of the image (07/13/2023), I get this error:
mkdir: cannot create directory ‘/new-folder’: Permission denied
If I change the image to the previous one (mcr.microsoft.com/mssql/server:2022-CU5-ubuntu-20.04
) it works well again.
So I have 2 questions:
- What can I do in my Dockerfile to enable folder creation with the latest image?
- Is it possible to see the Dockerfile of that SQLServer image, to understand this breaking change?
2
Answers
Change WORKDIR to a directory you actually have permission to create folders in.
This is not working because
/
is owned by root while you’re trying to create a folder with the default user that is the user of the parent image.You have to create the folder as root user:
then, if you want to change user, you should add the commands to create a new user, change the permission of that folder and set the new user. In this case, your Dockerfile becomes like that: