docker rmRemove containers
docker rm deletes stopped containers: their writable layer, config and logs. It refuses running containers unless you force it, and it leaves images and named volumes alone, so removing a container never deletes your database's data volume by accident.
docker rm [-f] [-v] CONTAINER [CONTAINER...]Yesterday's one-off containers are still around and their names block new ones.
docker rmDelete one or more containers. Same as docker container rm.
The CLI sends DELETE /containers/<id> (adding force=1 and v=1 for the flags). dockerd refuses if the container is running and force isn't set; with force it kills it first. Then it removes the container's network endpoints, unmounts and deletes its writable snapshot (everything the container wrote outside volumes), deletes /var/lib/docker/containers/<id> with the config and JSON log, and frees the name. The image is untouched. Volumes are reference-counted objects of their own: anonymous volumes (from VOLUME in the Dockerfile or -v /path) are deleted only with -v, and named volumes only by docker volume rm. That's why docker rm doesn't free the disk space a database has used.
-f, --forceKill a running container (SIGKILL) and remove it-v, --volumesAlso remove the container's anonymous volumes-l, --linkRemove a legacy --link, not the containerdocker container pruneRemove all stopped containers (with confirmation)prune --filter until=24hOnly those created more than 24 hours agodocker run --rmRemove the container automatically when it exitsdocker rm -f $(docker ps -aq) on a shared hostKills and deletes every container on the machine, including other people's and the databases.
Target by name or label: docker rm $(docker ps -aq --filter label=job=ci)Expecting docker rm to free a database's disk spaceNamed volumes are separate objects and are never removed by docker rm.
docker volume ls, then docker volume rm <name> once you're sureForgetting -v (or --rm) for throwaway containers from images with VOLUMEEach run leaves an anonymous volume behind; they pile up silently.
docker run --rm ... (removes anonymous volumes too), or docker rm -vTry these on a Linux machine of your own. Each task has a hint and a solution.
Remove all exited containers with the label job=ci, in a way that does nothing when there are none (there are none here: check it doesn't error).
Practise the xargs -r safety idea in the sandbox: find any *.tmp files in ~/data and delete them, without running rm when there are none.
Write the command to remove a stopped container named scratch-db together with its anonymous volumes.
docker rmRemove containers
docker rm deletes stopped containers: their writable layer, config and logs. It refuses running containers unless you force it, and it leaves images and named volumes alone, so removing a container never deletes your database's data volume by accident.
docker rm [-f] [-v] CONTAINER [CONTAINER...]Yesterday's one-off containers are still around and their names block new ones.
docker rmDelete one or more containers. Same as docker container rm.
The CLI sends DELETE /containers/<id> (adding force=1 and v=1 for the flags). dockerd refuses if the container is running and force isn't set; with force it kills it first. Then it removes the container's network endpoints, unmounts and deletes its writable snapshot (everything the container wrote outside volumes), deletes /var/lib/docker/containers/<id> with the config and JSON log, and frees the name. The image is untouched. Volumes are reference-counted objects of their own: anonymous volumes (from VOLUME in the Dockerfile or -v /path) are deleted only with -v, and named volumes only by docker volume rm. That's why docker rm doesn't free the disk space a database has used.
-f, --forceKill a running container (SIGKILL) and remove it-v, --volumesAlso remove the container's anonymous volumes-l, --linkRemove a legacy --link, not the containerdocker container pruneRemove all stopped containers (with confirmation)prune --filter until=24hOnly those created more than 24 hours agodocker run --rmRemove the container automatically when it exitsdocker rm -f $(docker ps -aq) on a shared hostKills and deletes every container on the machine, including other people's and the databases.
Target by name or label: docker rm $(docker ps -aq --filter label=job=ci)Expecting docker rm to free a database's disk spaceNamed volumes are separate objects and are never removed by docker rm.
docker volume ls, then docker volume rm <name> once you're sureForgetting -v (or --rm) for throwaway containers from images with VOLUMEEach run leaves an anonymous volume behind; they pile up silently.
docker run --rm ... (removes anonymous volumes too), or docker rm -vTry these on a Linux machine of your own. Each task has a hint and a solution.
Remove all exited containers with the label job=ci, in a way that does nothing when there are none (there are none here: check it doesn't error).
Practise the xargs -r safety idea in the sandbox: find any *.tmp files in ~/data and delete them, without running rm when there are none.
Write the command to remove a stopped container named scratch-db together with its anonymous volumes.