Understand the basic usage of docker desktop stop
In this step, we will learn the basic usage of the docker stop
command. The docker stop
command is used to stop one or more running containers. By default, the command sends a SIGTERM
signal to the container, and after a grace period, sends a SIGKILL
signal if the container has not stopped.
First, let's run a simple container that will stay running. We will use the ubuntu
image and run a command that keeps the container alive.
docker run -d ubuntu sleep infinity
The -d
flag runs the container in detached mode, meaning it runs in the background. sleep infinity
is a command that will make the container stay running indefinitely.
Now, let's list the running containers to get the container ID.
docker ps
You should see output similar to this, showing your running ubuntu
container:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
<container_id> ubuntu "sleep infinity" X seconds ago Up X seconds <container_name>
Replace <container_id>
with the actual ID of your running container from the output of docker ps
. Now, stop the container using the docker stop
command followed by the container ID.
docker stop <container_id>
After running this command, the container should stop. You can verify this by listing the running containers again.
docker ps
This time, the docker ps
command should not show the container you just stopped.
To see all containers, including those that are stopped, you can use the -a
flag with docker ps
.
docker ps -a
This will show you the stopped container with a status of Exited
.