It can be annoying to install a tool that is only needed a few times, and it would be preferable to avoid the installation process. However, sometimes it is necessary to use a tool to accomplish a specific task

Solution

To avoid the inconvenience of installing tools that are only needed occasionally, I have started using containerized tools instead. To make it easier to use these containerized tools, I have created a number of .bat files that wrap the docker run ... command and automatically mount the current working directory as a volume in the Docker container, and set the working directory in the Docker container to the mounted volume. These .bat files are placed in a directory that is included in the Path environment variable, so that they can be easily run from the command line or from an IDE. This allows me to use the tools inside the Docker container without having to type the docker run ... command every time.

Bat files to the rescue

The idea with the .bat files is to wrap the docker run ... invocation and automatically mount the current working directory into the container and set that as the working directory inside the container. The %* variable expands into the arguments passed to the bat file invocation, making it a very convinient way to pass arguments to the tool inside the container

Example bat file: ffmpeg

Heres an example of such a .bat file, for using ffmpeg from a container

@echo off
docker run --rm -it -v %CD%:/data --workdir /data jrottenberg/ffmpeg:5-alpine %*

This example is using an ffmpeg image from jrottenberg , since there is no official image for ffmpeg

Saving this in a .bat file named docker-ffmpeg.bat (or just ffmpeg.bat) and placing that in a directory that is included in Path allows for using ffmpeg from cmd or powershell

docker-ffmpeg -version

which gives the following output:

ffmpeg version 5.0.2 Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 10.2.1 (Alpine 10.2.1_pre1) 20201203
configuration: --disable-debug --disable-doc --disable-ffplay --enable-fontconfig --enable-gpl --enable-libaom --enable-libaribb24 --enable-libass --enable-libbluray --enable-libfdk_aac --enable-libfreetype --enable-libkvazaar --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libsrt --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxvid --enable-libzmq --enable-nonfree --enable-openssl --enable-postproc --enable-shared --enable-small --enable-version3 --extra-cflags=-I/opt/ffmpeg/include --extra-ldflags=-L/opt/ffmpeg/lib --extra-libs=-ldl --extra-libs=-lpthread --prefix=/opt/ffmpeg
libavutil      57. 17.100 / 57. 17.100
libavcodec     59. 18.100 / 59. 18.100
libavformat    59. 16.100 / 59. 16.100
libavdevice    59.  4.100 / 59.  4.100
libavfilter     8. 24.100 /  8. 24.100
libswscale      6.  4.100 /  6.  4.100
libswresample   4.  3.100 /  4.  3.100
libpostproc    56.  3.100 / 56.  3.100

Which gives an indication that things are working as intended.

Doing a conversion with the following command confirms it:

docker-ffmpeg -i test.mp4 -preset veryfast test.webm

Side-notes

Only current directory is available

My current approach is to use the %CD% variable to mount the current working directory as a volume in the Docker container. This means that only the files and directories in the current working directory are available inside the Docker container. This can be useful for accessing files that are needed by the tool inside the Docker container, and for storing the output of the tool in the current working directory.

Usage from other applications

When the -it arguments are included in the command, an error message similar to the input device is not a TTY may be displayed. To avoid this error, the -it arguments can be removed from the docker run .. command, so that the tool can run in a headless environment without requiring access to a TTY

Linux alternative

The linux alternative is just to create an alias instead of a .bat file. Such aliases could be added to the .profile file to be available everywhere

More bat files

You can find a couple more examples of in this my bat-launchers repository