In this lesson, you will learn how to temporarily freeze a running container without stopping the actual application process.
The Concept of "Pausing"
When you work with containers, sometimes you need to halt all activity to perform a quick task, like taking a consistent snapshot of the container's memory or saving its current state to disk, without killing the process inside.
Normally, when you "stop" a container, it sends a termination signal to the application, effectively shutting it down. However, pausing works differently. It leverages the Linux kernel’s ability to send a SIGSTOP signal to every process within the container’s cgroup. When this happens, the process is effectively "frozen" in its current tracks—it stops consuming CPU cycles, but its memory remains fully intact.
How to Freeze and Unfreeze
Because the container process is just a series of tasks managed by the underlying runtime (like runc), the daemon can communicate with the kernel to halt execution instantly.
To pause a container named my-web-app, you would use:
docker pause my-web-app
Once you run this, any request sent to that container will hang, as the process is no longer being scheduled on the CPU. The application doesn't know it has been paused; it simply waits for the signal to resume. To bring it back to life exactly where it left off, you use:
docker unpause my-web-app
Why it Matters
Unlike stopping and starting—which forces your application to reload its entire state, re-initialize database connections, and clear its memory—pausing is a "surgical" operation. The internal process state (the variables, the open network sockets, the file pointers) remains exactly as it was the moment you froze it. It is an ideal way to perform maintenance or state synchronization without incurring the "cold boot" penalty of a full restart.
Key Takeaway: Pausing suspends a container’s execution at the kernel level without terminating the process, allowing you to freeze the container's state in memory and resume it instantly.