I have a Python script that creates a folder and writes a file in that folder. I can open the file and see its contents, but unfortunately I cannot edit it. I tried to add the command, RUN chmod -R 777 .
but that didn't help either. In the created files and folders I see a lock sign as follows -
I have been able to recreate the same on a small demo. The contents are as follows -
demo.py
from pathlib import Path
Path("./created_folder").mkdir(parents=True, exist_ok=True)
with open("./created_folder/dummy.txt", "w") as f:
f.write("Cannot edit the contents of this file")
Dockerfile
FROM python:buster
COPY . ./data/
WORKDIR /data
RUN chmod -R 777 .
CMD ["python", "demo.py"]
docker-compose.yaml
version: "3.3"
services:
python:
working_dir: /data
build:
context: .
dockerfile: Dockerfile
volumes:
- .:/data/
After making these files run docker-compose up --build
and see the results and then try to edit and save the created file dummy.txt
- which should fail.
Any idea how to make sure that the created files can be edited and saved on the host?
EDIT:
- I am running docker-compose rootless. I had read that it is not a good idea to run docker with sudo, so I followed the official instructions on adding user group etc.
- I actually run the command
docker-compose up --build
not justdocker compose up
- I am on Ubuntu 20.04
username
is same for both~$ grep /etc/group -e "docker" docker:x:999:username ~$ grep /etc/group -e "sudo" sudo:x:27:username
- Tried using PUID and PGID environment variables... but still the same issue.
Current docker-compose file -
version: "3.3" services: python: working_dir: /data build: context: . dockerfile: Dockerfile volumes: - .:/data/ environment: - PUID=1000 - PGID=1000