Pause the running container
In the previous step, we ran a simple container that exited immediately. To demonstrate pausing and unpausing, we need a container that stays running. We will use a simple ubuntu
container and keep it running in the background.
First, let's pull the ubuntu
image.
docker pull ubuntu
You should see output indicating the image is being pulled and extracted.
Using default tag: latest
latest: Pulling from library/ubuntu
...
Status: Downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest
Now, let's run an ubuntu
container in detached mode (-d
) so it runs in the background. We will also give it a name (my-ubuntu
) for easier reference. We will use the tail -f /dev/null
command to keep the container running indefinitely.
docker run -d --name my-ubuntu ubuntu tail -f /dev/null
This command will output the container ID.
<container_id>
You can verify that the container is running using the docker ps
command.
docker ps
You should see output similar to this, showing your my-ubuntu
container with a status of Up
.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
<container_id> ubuntu "tail -f /dev/null" X seconds ago Up X seconds my-ubuntu
Now that we have a running container, we can pause it using the docker pause
command followed by the container name or ID.
docker pause my-ubuntu
If the command is successful, there will be no output. The container is now paused.