Skip to content

Instantly share code, notes, and snippets.

@NickAnderegg
Created October 8, 2021 19:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NickAnderegg/a3e30a22fe5e3e51b9b29484e83f5222 to your computer and use it in GitHub Desktop.
Save NickAnderegg/a3e30a22fe5e3e51b9b29484e83f5222 to your computer and use it in GitHub Desktop.
Using Docker to run CLI utilities with access to local files
#!/usr/bin/env bash
# This works only if all files specified as arguments below the PWD.
docker run --rm -it -v ${PWD}:${PWD} -w ${PWD} \
jrottenberg/ffmpeg:4.3-alpine -i input.mp4 -c copy output.mkv
# If you need input directories that aren't below your current PWD,
# you can mount a parent directory of the input files (preferably read-only
# with the narrowest possible scope) to an identical location in the
# container, and then reference those files absolutely.
docker run --rm -it -v /mnt:/mnt:ro -v ${PWD}:${PWD} -w ${PWD} \
jrottenberg/ffmpeg:4.3-alpine -i /mnt/dir1/input.mp4 -c copy output.mkv
# The standard way must be used if you want maximum specificity, but it makes
# commands less re-usable. However, it can simplify complex directory
# relationships.
docker run --rm -it \
-v /a/b/c/d/input:/mnt/input:ro -v /x/y/output:/mnt/output -w /mnt \
jrottenberg/ffmpeg:4.3-alpine -i input/file.mp4 -c copy output/file.mkv
# Some possible bash aliases to make it easier to run CLI utilities that can
# access local files.
alias run-pwd="docker run --rm -it -v ${PWD}:${PWD} -w ${PWD}"
alias run-mnt="docker run --rm -it -v /mnt:/mnt:ro -v ${PWD}:${PWD} -w ${PWD}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment