I want to use dpokidov/imagemagick.
Under Usage, it says that one can use the following convert command:
$ docker run -v /your/images:/imgs dpokidov/imagemagick /imgs/sample.png -resize 100x100 /imgs/resized-sample.png
This works, but every time I use this command, it creates a new container.
I could add --rm
to the command, so that the container gets removed after the command:
$ docker run -v /your/images:/imgs --rm dpokidov/imagemagick /imgs/sample.png -resize 100x100 /imgs/resized-sample.png
Is this the intended usage?
I was wondering whether there is a detached mode, so I could do something like this:
$ docker run -v /your/images:/imgs --name=my-imagemagick -d dpokidov/imagemagick
$ docker exec my-imagemagick convert /imgs/sample.png -resize 100x100 /imgs/resized-sample.png
In this way, I don't have to use docker run
, but it seems that there is no such mode.
Am I supposed to always use docker run
?
A docker container is just a regular process in a "bubble" (with its own file system and network, essentially). Launching one is not much heavier than starting a regular process (snap and flatpak installs work in a similar way....)
There is no point in keeping it around, like you would do for a VM, that has much more startup overhead. So yes, you can use docker run --rm
.
If you were to use it to process a large number of files, you could do a bit of optimization and use docker run
, loop on docker exec
, and then docker stop
but it would be even better to have the "loop" done in the container or even by IM itself.
Also, don't overlook the possibility to "derive" your own docker image from the IM image to specialize it and adapt it to you needs (add scripts, change the default command, etc...).