How to use docker container unpause command to resume containers

DockerDockerBeginner
Practice Now

Introduction

In this lab, you will learn how to manage the state of Docker containers, specifically focusing on pausing and unpausing them. You will begin by creating and running a simple container.

Following the creation, you will practice pausing the running container and verifying its paused state. Finally, you will learn how to unpause the container and confirm that it has resumed execution. This hands-on experience will provide a practical understanding of using the docker container unpause command.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL docker(("Docker")) -.-> docker/ContainerOperationsGroup(["Container Operations"]) docker(("Docker")) -.-> docker/ImageOperationsGroup(["Image Operations"]) docker/ContainerOperationsGroup -.-> docker/run("Run a Container") docker/ContainerOperationsGroup -.-> docker/ps("List Running Containers") docker/ContainerOperationsGroup -.-> docker/start("Start Container") docker/ContainerOperationsGroup -.-> docker/stop("Stop Container") docker/ContainerOperationsGroup -.-> docker/rm("Remove Container") docker/ImageOperationsGroup -.-> docker/pull("Pull Image from Repository") subgraph Lab Skills docker/run -.-> lab-555126{{"How to use docker container unpause command to resume containers"}} docker/ps -.-> lab-555126{{"How to use docker container unpause command to resume containers"}} docker/start -.-> lab-555126{{"How to use docker container unpause command to resume containers"}} docker/stop -.-> lab-555126{{"How to use docker container unpause command to resume containers"}} docker/rm -.-> lab-555126{{"How to use docker container unpause command to resume containers"}} docker/pull -.-> lab-555126{{"How to use docker container unpause command to resume containers"}} end

Create and run a container

In this step, you will learn how to create and run a Docker container. A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another.

First, let's pull a simple image from Docker Hub. We will use the hello-world image, which is a very small image used to test Docker installations.

docker pull hello-world

You should see output indicating that the image is being pulled and extracted.

Using default tag: latest
latest: Pulling from library/hello-world
...
Status: Downloaded newer image for hello-world:latest
docker.io/library/hello-world:latest

Now that we have the image, we can run a container based on this image. When you run a container from the hello-world image, Docker will simply print a message to your terminal and then exit.

docker run hello-world

You should see output similar to this, which confirms that your Docker installation is working correctly:

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (If you already had the image locally, skipped the pull step.)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

This command created and ran a container from the hello-world image. Since the container's job was just to print a message and exit, it is no longer running.

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.

Verify the container is paused

In the previous step, we paused the my-ubuntu container. Now, let's verify that the container is indeed in a paused state.

We can use the docker ps command again to check the status of running containers.

docker ps

This command will only show currently running containers. Since we paused the my-ubuntu container, it should not appear in the output of docker ps.

CONTAINER ID   IMAGE     COMMAND    CREATED    STATUS    PORTS     NAMES

To see all containers, including those that are stopped, exited, or paused, we can use the -a flag with docker ps.

docker ps -a

Now you should see the my-ubuntu container listed, and its status should indicate that it is paused. Look for the word Paused in the STATUS column.

CONTAINER ID   IMAGE          COMMAND               CREATED         STATUS                   PORTS     NAMES
<container_id>   ubuntu         "tail -f /dev/null"   X minutes ago   Up X minutes (Paused)             my-ubuntu

The (Paused) status confirms that the container is not actively running but is still in memory, ready to be unpaused.

Unpause the container

In the previous step, we verified that the my-ubuntu container was paused. Now, let's unpause it and resume its execution.

To unpause a container, we use the docker unpause command followed by the container name or ID.

docker unpause my-ubuntu

If the command is successful, there will be no output. The container should now be running again from where it was paused.

Verify the container is running again

In the previous step, we unpaused the my-ubuntu container. Now, let's verify that it is actively running again.

We can use the docker ps command to list currently running containers.

docker ps

This time, the my-ubuntu container should appear in the output, and its status should be Up.

CONTAINER ID   IMAGE          COMMAND               CREATED         STATUS         PORTS     NAMES
<container_id>   ubuntu         "tail -f /dev/null"   X minutes ago   Up X seconds             my-ubuntu

The Up status indicates that the container is running and its processes are active.

To further confirm, we can also use docker ps -a and check the status. It should show Up without the (Paused) indicator.

docker ps -a
CONTAINER ID   IMAGE          COMMAND               CREATED         STATUS         PORTS     NAMES
<container_id>   ubuntu         "tail -f /dev/null"   X minutes ago   Up X seconds             my-ubuntu

This confirms that the container has successfully resumed from its paused state.

Finally, let's clean up the container we created. We need to stop it first, then remove it.

docker stop my-ubuntu

This command will stop the container. You should see the container name or ID printed.

my-ubuntu

Now, remove the container using the docker rm command.

docker rm my-ubuntu

This command will remove the container. You should see the container name or ID printed.

my-ubuntu

Summary

In this lab, you learned how to create and run a Docker container by pulling the hello-world image and executing it. This demonstrated the basic process of obtaining an image and launching a container from it. You then learned how to pause a running container, effectively suspending its processes, and verify its paused state. Finally, you practiced unpausing the container to resume its execution and confirmed that it was running again.