you can run docker container to do some non-interactive processing. eg with:
docker run --rm myalgo:4.2 --foo --bar
when you need to do it interactively, you just add -it
:
docker run -it --rm myalgo:4.2 --foo --bar
so far, so good. now how about CI scripts, that on CI server are being run in a non-interactive way, but you also want the very same scripts to be runnable interactively by developers (so that they can eg. ^C
it during the run)? it turns out it is fairly simple with tty
command to detect if terminal is interactive or not and bash arrays to pass parameters to docker
:
EXTRA_FLAGS=() if tty -s then EXTRA_FLAGS+=("-it") fi docker run \ "${EXTRA_FLAGS[@]}" \ --rm \ myalgo:4.2 --foo --bar
as a free bonus you can now add multiple optional flags, to the same array and/or use it for all the arguments, to simplify the invocation of docker
.