1

I'm currently trying to mount a Docker container directory to my local host directory. My local folder has the path C:/Users/lp/local_env-Returns/ and has the following files: cmi_forecast_script.py , Dockerfile, requirements.txt , .dockerignore and sales_data.xlsx. I'm running the Python script when I run the Docker container of the Dockerfile. This creates a csv_file in my Docker container. The path of the csv_file in the container is /cmi_forecast_script/7789-10033.csv. Now I want that I have the csv-file also in my local-directory. I already tried to mount the two paths with docker run -v /Users/lp/local_env-Returns/:/cmi_forecast_script/ <image name>. But then I get: python: can't open file 'cmi_forecast_script.py': [Errno 2] No such file or directory. Where is the problem?

PS: I also tried docker run -v /Users/lp/local_env-Returns/:/cmi_forecast_script/cmi_forecast_script.py <image name> but then I get another error which is too long to post here.

My Dockerfile:

FROM python:3.8-slim-buster
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
COPY requirements.txt .
RUN pip install -r requirements.txt
WORKDIR /cmi_forecast_script
COPY . /cmi_forecast_script
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /cmi_forecast_script
USER appuser
CMD ["python", "cmi_forecast_script.py"]`
Daniel Widdis
  • 8,424
  • 13
  • 41
  • 63
  • Are you on Windows? The path you're mounting `/Users/...` is not the same as you say above `C:/Users/...`. Check it out – Saeed Sep 21 '21 at 06:24
  • Yes, I am on Windows, but when adding C:/... it also doesn`t work. I think because of the : after the C – LennartPfeiler Sep 21 '21 at 06:31
  • Check https://stackoverflow.com/questions/60916317/using-docker-for-windows-to-volume-mount-a-windows-drive-into-a-linux-container if solves your mounting issue and then update – Saeed Sep 21 '21 at 06:42
  • So now I tried `docker run -v "/C/Users/lp/local_env-Returns/:/cmi_forecast_script/" localenvreturns`, but I'm getting the same error – LennartPfeiler Sep 21 '21 at 06:50
  • Your queue for edit is full. Please edit your question in a more readable way and then let me know if I can help. Also check if `local_env-Returns` is a directory or a file. – Saeed Sep 21 '21 at 06:57
  • local_env-Returns is a folder – LennartPfeiler Sep 21 '21 at 08:22
  • 1
    I think the issue is with your `Dockerfile` `COPY` command. Check https://stackoverflow.com/questions/46309423/dockerfile-copy-from-a-windows-file-system-to-a-docker-container. You cannot – Saeed Sep 21 '21 at 10:50

0 Answers0