I would like to pass a file from the host system to a container at runtime. I want to run a CLI tool within a container and use the file as an argument to the CLI tool. Is it possible to modify the following command: docker run -it --rm --name <container-name> to achieve what I want to do. The docker cp command doesn’t work for what I need since it doesn’t run from within the container and I need to pass the file name as an argument.
I usually use the -v "$PWD:$PWD" -w "$PWD" trick. Run container and volume mount the current host working directory into the container at the same path and set working directory to same path.
So for example if I want to transcode a wav file on the host to a mp3 file usig ffmpeg running in a container I would do:
docker run --rm -v "$PWD:$PWD" -w "$PWD" mwader/static-ffmpeg:4.2.2 -i file.wav file.mp3
You can also add -u $UID:$GROUPS if your unsure what default user the image runs as.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With