I have a python script which changes the first line of a file, and it works locally but not when running the docker container.
Directory structure
my_workdir
├─── Dockerfile
├─── docker-compose.yml
├─── script.py
└─── data
    └─── r2.txt
this is my python code
a_file = open("data/r2.txt", "r")
list_of_lines = a_file.readlines()
list_of_lines[0] = "1\n"
a_file = open("data/r2.txt", "a")
a_file.writelines(list_of_lines)
a_file.close()
it basically changes the first line inside "r2.txt" to "1" but when I check the txt file is not changing it. I was reading that you need to mount a volume so I added the following to my docker-compose.yml file
version: "3"
services:
  app:
    image: imagen-c1
    container_name: c1
    privileged: true
    deploy:
      replicas: 1
      update_config:
        parallelism: 1
        delay: 5s
      restart_policy:
        condition: on-failure
    build: .
    environment:
      - DISPLAY=${DISPLAY}
      - LEGACY_IPTABLES=true 
    volumes:
      - /tmp/.X11-unix:/tmp/.X11-unix
      - ./:/data #HERE IS THE VOLUME
this is my dockerfile
FROM python:3.9-alpine
RUN pip install selenium
RUN apk add chromium
RUN apk add chromium-chromedriver
ENV CHROME_BIN=/usr/bin/chromium-browser \
    CHROME_PATH=/usr/lib/chromium/
ENV HOME /home/user-machine
    
RUN pip install webdriver_manager
WORKDIR ./
COPY ["script.py", "data/", "./"]
CMD python3 script.py
maybe I'm not doing it correctly because the file remains the same.
 
    