I'm trying to build a docker container for my python application that allow edits to a config file in the application's working directory so I don't need to rebuild the image every time a change is made.
Dockerfile:
FROM python:3
VOLUME /app
COPY . /app
WORKDIR /app
RUN pip install requirements.txt
CMD ["python", "main.py"]
Once the image is built I deploy the container with
docker run -d --name app -v /path/on/host/app:/app app:latest
I get an error in the container, python: can't open file 'main.py': [Errno 2] No such file or directory
and /path/on/host/app
stays empty.
I can't figure out what I need in my Dockerfile to make this work.
Update - Found a solution
Since I only need access to the config file here are the changes I made to get this to work
Dockerfile:
FROM python:3
COPY . /app
WORKDIR /app
RUN pip install requirements.txt
VOlUME /app/config
CMD ["python","main.py"]
Now when I run the container I copy the config to /path/on/host/app
docker run -d --name app --mount type=bind,source=/path/on/host/app,target=/app/config
This solved my issue and now I can update the config and restart the container to get the changes to apply.