skip to Main Content

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:

  1. What can I do in my Dockerfile to enable folder creation with the latest image?
  2. Is it possible to see the Dockerfile of that SQLServer image, to understand this breaking change?

2

Answers


  1. Change WORKDIR to a directory you actually have permission to create folders in.

    Login or Signup to reply.
  2. 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:

    FROM mcr.microsoft.com/mssql/server:latest
    USER root
    RUN mkdir -p /newfolder
    

    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:

    FROM mcr.microsoft.com/mssql/server:latest
    USER root
    RUN mkdir -p /newfolder
    RUN useradd -r newuser
    RUN chown newuser:newuser /newfolder
    USER newuser
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search