Home > Blockchain >  Passing folder as argument to a Docker container with the help of volumes
Passing folder as argument to a Docker container with the help of volumes

Time:04-01

I have a python script that takes two arguments -input and -output and they are both directory paths. I would like to know first if this is a recommended use case of docker, and I would like to know also how to run the docker container by specifying custom input and output folders with the help of docker volume. My post is similar to this : Passing file as argument to Docker container. Still I was not able to solve the problem.

CodePudding user response:

Its common practice to use volumes to persist data or mount some input data. See the postgres image for example.

docker run -d \
  --name some-postgres \
  -e PGDATA=/var/lib/postgresql/data/pgdata \
  -v /custom/mount:/var/lib/postgresql/data \
  postgres

You can see how the path to the data dir is set via env var and then a volume is mounted at this path. So the produced data will end up in the volume.

You can also see in the docs that there is a directory /docker-entrypoint-initdb.d/ where you can mount input scripts, that run on first DB setup.

In your case it might look something like this.

docker run  \
  -v "$PWD/input:/app/input" \
  -v "$PWD/output:/app/output"  \
  myapp --input /app/input --output /app/output 

Or you use the same volume for both.

docker run  \
  -v "$PWD/data:/app/data" \
  myapp --input /app/data/input --output /app/data/output 
  • Related