Permission denied when creating a directory inside Docker container – Docker

by
Ali Hasan
boot2docker dockerfile llama-cpp-python user-permissions zipkin

Quick Fix: Modify your Dockerfile by adding change ownership and permissions of the directory where you want to create a file or directory as below:

USER root
RUN mkdir <directory_name> & chown -R <user_name>:<user_name> <directory_name>

The Problem:

While creating a directory inside a Docker container using the ‘os.makedirs’ function, a ‘Permission denied’ error occurs. The user running the container (user 1000) does not have sufficient permissions to create the directory. The Dockerfile does not specify any specific permissions for the user. As a result, the user does not have the necessary permissions to create the directory.

The Solutions:

Solution 1: Change ownership of the /app/data directory

You can modify your Dockerfile to change the ownership of the /app/data directory to the nonroot user. This will grant the user with UID 1000 (nonroot) write access to the directory and allow you to create the /app/data/model directory and extract into it succesfully.

USER root
RUN mkdir /app/data &amp;&amp; chown -R nonroot:nonroot /app/data

Q&A

Do user 1000 has permission to create a directory inside docker?

The user inside the Docker container does not have write access to the /app/data directory because user 1000(nonroot) does not have write access to the /app/data directory.

Video Explanation:

The following video, titled "”[Solved", provides additional insights and in-depth exploration related to the topics discussed in this post.

Play video

This video provides further insights and detailed explanations related to the content discussed in the article.

How To Fix Permission Denied Error inside Docker …” description=”[Solved] How To Fix Permission Denied Error inside Docker Container? Docker Non-Root User Error Note: If you click on one of the link, …”]