Stopping a container
We can stop one or more containers at once. In this recipe, we will first start a container and then stop it.
Getting ready
Ensure that the Docker daemon is running on the host and can be connected through the Docker client. You will also need one or more running containers.
How to do it...
To stop a container, run the following command:
docker container stop [OPTIONS] CONTAINER [CONTAINER...]
Or run the following legacy command:
docker stop [OPTIONS] CONTAINER [CONTAINER...]
If you already have running containers, then you can go ahead and stop them; otherwise, we can create one and then stop it as follows:
$ ID=$(docker run -d -i ubuntu /bin/bash)$ docker stop $ID
How it works...
This will move the container from a running state to a stop state by stopping the process running inside the container. A stopped container can be be started again, if needed.
There's more...
To stop a container after waiting for some time, use the --time/-t
option.
To stop all running containers, run the...