Search code examples
javadockerffmpegdocker-java

How to play a docker run --rm with docker-java?


In our J2EE project, we want to call sjourdan/ffmpeg docker through the docker-java library.

A typical call for ffmpeg conversion will be something like:

docker run --rm -v /e/data:/tmp/workdir sjourdan/ffmpeg -i /tmp/workdir/test.mov -f mp4 -vcodec libx264 -acodec aac /tmp/workdir/test.mp4

We managed all of that with a DockerClient.createContainerCmd() and the right .with() methods, except for the --rm argument.

Is there a way to add it through docker-java?


Solution

  • For the current version, which is 3.2.8, you can set the autoremove option with:

    dockerClient.createContainerCmd(image).withHostConfig(new HostConfig().withAutoRemove(true)).exec()