I would like to suspend a Docker container and resume later. How can this be done? By suspending I mean that it should save the state of ongoing process (e.g. video encoding) and then resume it back at any time.
To resume Docker Desktop, click either the Resume button in the menu or type any Docker CLI command in your terminal. To try out this feature on Docker Desktop 4.2, navigate to the whale menu and click the 'Pause' button.
Pause Container If we want to pause the processes running inside the container, we can use the “docker pause” command. To unpause the container, use “docker unpause” command.
To stop one or more running Docker containers, you can use the docker stop command. The syntax is simple: $ docker stop [OPTIONS] CONTAINER [CONTAINER...]
Your answerThe main process inside the container will receive SIGTERM, and after a grace period, SIGKILL. This will stop a running container. This would restart the container.
As of Version 0.12.0, Docker supports PAUSE
and UNPAUSE
commands to pause and resume containers using cgroup freezer.
AFAIK right now it can't be done with pure docker but lxc supports that. I've play around little bit with docker and confirmed that this can be done with lxc-freeze -n <containtr.id>
and to resume operations lxc-unfreeze -n <container.id>
But in v0.2.0 docker ps gives you only shorten containter id even with -notrunc and lxc-ls output is empty on my system (strange, need to read more about it, as docker uses plain lxc-start with params so lxc-ps should print this). I found full container id with lxc-ps
. It would be nice to add docker freeze command. Maybe it's time for me to learn some go :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With