-1

I am creating a docker container in which I want to give file path from command line arguments and then do some process on the given input file. And after completing the process, output should be stored in the same file path folder.

For example: I have a "input1.csv" file in "F:\Ekanshu\data\" folder. I want to give "input1.csv" file as input file from command line arguments. Then python code inside docker container will do some process on the "input1.csv" file. After completing the process, "output1.csv" file should be stored in the "F:\Ekanshu\data\" folder.

Folder Structure:-

Docker Application Folder ("F:\Ekanshu\demoapp"):

├── models
    ├── model.h5
    ├── model.json
├── app.py
├── Dockerfile
├── requirements.txt

Input File Folder ("F:\Ekanshu\data\"):

├── input1.csv
├── input2.csv
├── input3.csv

My Dockerfile:-

FROM alpine:latest
FROM python:3.7
RUN pip install --no-cache-dir --upgrade pip
COPY requirements.txt /app/requirements.txt
WORKDIR /app
RUN pip install -r requirements.txt
RUN pip install https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.0.0/en_core_web_sm-3.0.0.tar.gz
RUN ["python", "-c", "import nltk; nltk.download('all')"]
COPY . /app
ENTRYPOINT ["python", "app.py"]

Below commands I am running inside "F:\Ekanshu\demoapp\" folder:-

To build docker container:- docker build –t myapp:latest .

To run docker container:- docker run -it myapp:latest F:\\Ekanshu\\data\\input1.csv

How can I give "F:\Ekanshu\data\input1.csv" as input file path from command line arguments and store the output "output1.csv" in the "F:\Ekanshu\data\" folder?

Ekanshu
  • 69
  • 1
  • 11
  • Docker is designed so that containers generally can't read and write host directories. Could you run this process without Docker, in a Python virtual environment on the host? – David Maze Jun 25 '21 at 11:59

1 Answers1

1

At runtime, docker containers have very little access to anything on the host computer unless you specifically allow it. For instance, it doesn't have access to the host filesystem.

To give the container access to the host file system, you can map part of the host file system using a volume mapping.

If you run your container with the option -v F:\\Ekanshu\\data\\input1.csv:/data/input1.csv, your file will be accessible inside the container on the path /data/input1.csv. You can then add the filename as a parameter to your python script like this

docker run -it -v F:\\Ekanshu\\data\\input1.csv:/data/input1.csv myapp:latest /data/input1.csv
Hans Kilian
  • 18,948
  • 1
  • 26
  • 35