Python – How to create a directory inside docker with permissions


I have the following docker-compose.yml file:

version: '3'
    build: .
    container_name: my_container
    network_mode: "host"
      - ./script:/script

and the following Dockerfile

FROM python:latest
COPY . .
CMD [ "python", "./script/"]

import os
os.makedirs('/script/my_new_folder_timestamp_here', 0o0777)

The script creates a directory inside the container, with a name that is only known at run time (i.e with timestamp). That directory is created by default with root permissions and it can be accessed from host due to the created volume.
That means in order to access the folder from host, I can only do so as root.

My question is, how can I create a directory with python, inside the docker container, and be able to access it from host without root permission?

The objective is, in the dynamically created directory, there will be files that the user can load on a web app, using the HTML Input Element. This is not possible if the directory or the files in it are root protected.

Source: Docker Questions

Categorised as docker, python Tagged ,


Leave a Reply

Still Have Questions?

Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us