Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 334
Xavier Portebois Avatar asked Feb 27 '26 01:02

Xavier Portebois


1 Answers

According to this other StackOverflow question/answer, --rm is not handled by the Docker API, so we got no luck with docker-java either.

So, in the end we carefully remove the container after the execution, something like:

dockerClient.startContainerCmd(container.getId()).exec();
// do some stuff
dockerClient.removeContainerCmd(container.getId()).withForce(true).exec();
like image 176
Xavier Portebois Avatar answered Feb 28 '26 15:02

Xavier Portebois



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!