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:
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:
docker: Error response from daemon: OCI runtime create failed: container_linux.go:370: starting container process caused: process_linux.go:459: container init caused: rootfs_linux.go:59: mounting "/run/desktop/mnt/host/wsl/docker-desktop-bind-mounts/Ubuntu-20.04/b7a1f88831c4798ba3c6d7e051f46369d24df9d13ea920a00ef6d8026919db31" to rootfs at "/var/lib/docker/overlay2/c7d248315603fd75df06d5f319f03d2d7c0ddda3e3ed8c05d180fe6c167d000e/merged/cmi_forecast_script/cmi_forecast_script.py" caused: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type.
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"]`
Source: Python Questions