Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the Docker remote API have an equivalent for "docker run --rm ..."?

Tags:

docker

I'd like to be able to easily clean up containers after they exit. Is this possible with the remote API? (Other than discovering the exit myself and removing with the DELETE/containers endpoint)

like image 628
shino Avatar asked Feb 12 '15 02:02

shino


People also ask

What is docker run rm?

Docker Run The --rm causes Docker to automatically remove the container when it exits. The image being used to create the container is generally specified as <name>:<tag> such as ruby:latest .

Does docker have a REST API?

The Docker Engine API is a RESTful API accessed by an HTTP client such as wget or curl , or the HTTP library which is part of most modern programming languages.


2 Answers

larsks answer is now outdated. Docker Remote API 1.25 shifted --rm functionality from client to server. There is an AutoRemove flag under HostConfig when creating a container that does exactly this.

like image 161
Josh Avatar answered Oct 04 '22 13:10

Josh


The --rm option in the Docker client is entirely a client side option. This is, for example, why you can't combine -d with --rm -- because the client is only able to remove the container on exit if it stays attached to the container.

You could write a clean up script that would periodically run docker ps -f status=exited -q and clean up the result.

You could also achieve something more automated by monitoring the Docker API's /events endpoint and responding immediately to container exits, I guess.

like image 36
larsks Avatar answered Oct 04 '22 12:10

larsks