{"id":131817,"date":"2023-02-13T08:00:00","date_gmt":"2023-02-13T08:00:00","guid":{"rendered":"https:\/\/fedoramagazine.org\/?p=37801"},"modified":"2023-02-13T08:00:00","modified_gmt":"2023-02-13T08:00:00","slug":"podman-checkpoint","status":"publish","type":"post","link":"https:\/\/sickgaming.net\/blog\/2023\/02\/13\/podman-checkpoint\/","title":{"rendered":"Podman Checkpoint"},"content":{"rendered":"<p>Podman is a tool which runs, manages and deploys containers under the <a href=\"https:\/\/opencontainers.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">OCI<\/a> standard. Running containers with rootless access and creating pods (a Pod is a group of containers ) are additional features of Podman. This article describes and explains how to use checkpointing in Podman to save the state of a running container for later use.<\/p>\n<p> <span id=\"more-37801\"><\/span> <\/p>\n<p><strong>Checkpointing Containers : <\/strong>Checkpoint \/ Restore In User-space, or CRIU, is Linux software available in the Fedora Linux repository as the &#8220;criu&#8221; package. It can freeze a running container (or an individual application) and checkpoint its state to disk (Reference : <a href=\"https:\/\/criu.org\/Main_Page\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/criu.org\/Main_Page<\/a>).&nbsp;The saved data can be used to restore the container and run it exactly as it was during the time of the freeze. Using this, we can achieve live migration, &nbsp;snapshots, or remote debugging of applications or containers. This capability requires CRIU 3.11 or later installed on the system.&nbsp;<\/p>\n<h2>Podman Checkpoint <\/h2>\n<pre class=\"wp-block-preformatted\"># podman container checkpoint &lt;containername&gt; <\/pre>\n<p>This command will create a checkpoint of the container and freeze its state. Checkpointing a container will stop the running container as well. If you do <em>podman ps<\/em> there will be no container existing named &lt;containername&gt;. <\/p>\n<p>You can export the checkpoint to a specific location as a file and copy that file to a different server<\/p>\n<pre class=\"wp-block-preformatted\"># podman container checkpoint &lt;containername&gt; -e \/tmp\/mycheckpoint.tar.gz<\/pre>\n<h2>Podman Restore <\/h2>\n<pre class=\"wp-block-preformatted\"># podman container restore --keep &lt;containername&gt; <\/pre>\n<p>the <em>&#8211;keep<\/em> option will restore the container with all the temporary files.<\/p>\n<p>To import the container checkpoint you can use: <\/p>\n<pre class=\"wp-block-preformatted\"># podman container restore -i \/tmp\/mycheckpoint.tar.gz<\/pre>\n<h2>Live Migration using Podman Checkpoint<\/h2>\n<p>This section describes how to migrate a container from client1 to client2 using the podman checkpoint feature. This example uses the <a href=\"https:\/\/lab.redhat.com\/tracks\/rhel-system-roles\">https:\/\/lab.redhat.com\/tracks\/rhel-system-roles<\/a> playground provided by Red Hat as it has multiple hosts with ssh-keygen already configured. <\/p>\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2023\/02\/podman-checkpoint-5.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"334\" src=\"https:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2023\/02\/podman-checkpoint.png\" alt=\"\" class=\"wp-image-37839\" \/><\/a><\/figure>\n<p>The example will run a container with some process on client1, create a checkpoint, and migrate it to client2. First run a container on the client1 machine with the commands below:<\/p>\n<pre class=\"wp-block-preformatted\">podman run --name=demo1 -d docker.io\/httpd\npodman exec -it demo1 bash\nsleep 600&amp; (run a process for verification )\nexit<\/pre>\n<p>The above snippet runs a container as demo1 with the httpd process which runs a sleep process for 600 seconds ( 10 mins ) in background. You can verify this by doing:<\/p>\n<pre class=\"wp-block-preformatted\"># podman top demo1 USER PID PPID %CPU ELAPSED TTY TIME COMMAND\nroot 1 0 0.000 5m40.61208846s ? 0s httpd -DFOREGROUND www-data 3 1 0.000 5m40.613179941s ? 0s httpd -DFOREGROUND www-data 4 1 0.000 5m40.613258012s ? 0s httpd -DFOREGROUND www-data 5 1 0.000 5m40.613312515s ? 0s httpd -DFOREGROUND root 88 1 0.000 16.613370018s ? 0s sleep 600<\/pre>\n<p>Now create a container checkpoint and export it to a specific file:<\/p>\n<pre class=\"wp-block-preformatted\"># podman container checkpoint myapache2 -e \/tmp\/mycheckpoint.tar.gz\n# scp \/tmp\/mycheckpoint.tar.gz client2:\/tmp\/<\/pre>\n<p>Then on client2:<\/p>\n<pre class=\"wp-block-preformatted\"># cd \/tmp\n# podman container restore -i mycheckpoint.tar.gz\n# podman top demo1<\/pre>\n<p>You should see the output as follows:<\/p>\n<pre class=\"wp-block-preformatted\">USER PID PPID %CPU ELAPSED TTY TIME COMMAND\nroot 1 0 0.000 5m40.61208846s ? 0s httpd -DFOREGROUND www-data 3 1 0.000 5m40.613179941s ? 0s httpd -DFOREGROUND www-data 4 1 0.000 5m40.613258012s ? 0s httpd -DFOREGROUND www-data 5 1 0.000 5m40.613312515s ? 0s httpd -DFOREGROUND root 88 1 0.000 16.613370018s ? 0s sleep 600<\/pre>\n<p>In this way you can achieve a live migration using the podman checkpoint feature.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Podman is a tool which runs, manages and deploys containers under the OCI standard. Running containers with rootless access and creating pods (a Pod is a group of containers ) are additional features of Podman. This article describes and explains how to use checkpointing in Podman to save the state of a running container for [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":131818,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48],"tags":[45,61,46,47],"class_list":["post-131817","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-fedora-os","tag-fedora","tag-fedora-project-community","tag-magazine","tag-news"],"_links":{"self":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/131817","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/comments?post=131817"}],"version-history":[{"count":0,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/131817\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media\/131818"}],"wp:attachment":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media?parent=131817"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/categories?post=131817"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/tags?post=131817"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}