Stop and remove containers

Modified: 21 Oct 2024 22:57 UTC

Watch the screencast

Watch the video to see docker stop and docker rm in action.

Stop containers

With docker stop, a container is given a graceful shutdown. This could be useful if your container is not responsive, or if you need to restart the container in order to upgrade or migrate to another host.

Docker automatically gives your container 10 seconds to stop, and if it does not comply, the process is forcibly killed. It is possible to allocate a specific amount of time for the shutdown by adding --time=<seconds> before the container name. For example, docker stop --time=30 <container name> would give the container 30 seconds to stop gracefully before it is forcibly killed.

The companion triton command, triton instance stop, is similar to docker stop and will stop your instances.

Remove containers

To remove a container you're no longer using (and has been previously stopped), execute docker rm <container name>. If you want to remove a container that is not already stopped, you can force stop and remove the container with docker rm -f <container name>.

On Triton, triton instance delete <container name> can remove any container, including Docker containers.

You will be billed for all provisioned containers, including those which are stopped. To avoid charges for containers which you may no longer be using, be sure to remove them.