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

I would like to be able to easily clean the containers after they come out. Is this possible using the remote API? (Besides detecting the exit itself and deleting with the DELETE endpoint / containers)

+8
docker
source share
2 answers

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

You can write a cleanup script that will periodically run docker ps -f status=exited -q and clear the result.

You can also achieve something more automated by controlling the endpoint of the Docker API /events and, I believe, will immediately respond to the container outputs.

+7
source share

Larsks answer is now deprecated. Docker Remote API 1.25 changes --rm functionality from client to server . There is an AutoRemove flag under HostConfig when creating a container that does just that.

+1
source share

All Articles