Search code examples
python-3.xdockerinputoutputdocker-volume

Docker file with input/output files from multiple locations


I have a python program, that takes lots of different inputs (but lets just say -i for input file and -db for database and -o for output file, that the program creates.) So I would run the program like this: python3 myprogram.py -i /path/to/inputfile -db /another/path/to/database -o /a/different/path/to/outputfile This program runs with no problems through the command line.

Now I am trying to make a dockerfile, that runs this program. I would like to be able to use inputfiles and database files outside the docker (so I can use multiple different files every time I run the container). And I also want to be able to access the output file outside the container.

I know I can use volumes, but I have only seen examples with 1 path to 1 inputfile. What if there are multiple inputfiles and outputfiles, that I want to access outside the container?

My Dockerfile ends with:

ENTRYPOINT ["python3", "/usr/src/myprogram.py"]

So, how can I achieve this? I have been searching and searching, any help would be appreciated.


Solution

  • You can use as many volumes as you like but you need to specify them during container launch, not in Dockefile. That is

    docker run -v /host/path:/container/path some_image:latest command
    

    You can mount several directories with multiple -v keys.