Changes

1,110 bytes added ,  18:56, 9 October 2025
m
Line 3: Line 3:  
== Container Checkpoint/Restore ==
 
== Container Checkpoint/Restore ==
   −
$ mkdir -p alpine-container/rootfs && cd alpine-container
+
Create a container rootfs
 +
<pre>
 +
mkdir -p alpine-container/rootfs && cd alpine-container
 +
wget https://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/x86_64/alpine-minirootfs-3.22.2-x86_64.tar.gz
 +
tar -xzf alpine-minirootfs-3.22.2-x86_64.tar.gz -C rootfs
 +
rm -f alpine-minirootfs-3.22.2-x86_64.tar.gz
 +
</pre>
   −
$ wget https://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/x86_64/alpine-minirootfs-3.22.2-x86_64.tar.gz && \
+
Create a container specification file:
  tar -xzf alpine-minirootfs-3.22.2-x86_64.tar.gz -C rootfs && \
  −
  rm -f alpine-minirootfs-3.22.2-x86_64.tar.gz
     −
$ runc spec
+
<pre>
 +
runc spec
 +
</pre>
   −
$ sed -i 's/"sh"/\"sh -c '\''i=0; while true; do echo $i; i=$(expr $i + 1); sleep 1; done'\'\"'/' config.json
+
Set a command to run in the container:
   −
$ sed -i 's/"terminal": true/"terminal": false/g' config.json
+
<pre>
 +
sed -i 's/"sh"/"sh", "-c", "i=0; while true; do echo $i; i=$(expr $i + 1); sleep 1; done"/' config.json
 +
</pre>
   −
$ runc run -d looper 0</dev/null 1>/dev/null 2>/dev/null
+
Start the container and redirect the output/error to <code>looper.out</code> and <code>looper.out</code>:
 +
 
 +
<pre>
 +
sudo runc run looper 0</dev/null 1>looper.out 2>looper.err &
 +
</pre>
 +
 
 +
Alternatively, you can disable the interactive terminal and run container in the background as follows:
 +
 
 +
<pre>
 +
sed -i 's/"terminal": true/"terminal": false/g' config.json
 +
sudo runc run -d looper 0</dev/null 1>/dev/null 2>/dev/null
 +
</pre>
 +
 
 +
Show running containers
 +
 
 +
<pre>
 +
sudo runc list
 +
sudo runc state looper
 +
</pre>
 +
 
 +
Now the container can be checkpointed:
 +
 
 +
<pre>
 +
mkdir /tmp/checkpoint
 +
sudo runc checkpoint --image-path /tmp/checkpoint --work-path /tmp/checkpoint looper
 +
</pre>
 +
 
 +
Once the container is checkpointed it will be no longer visible in <code>runc list</code>.
 +
 
 +
The following command can be used to restore the container:
 +
 
 +
<pre>
 +
sudo runc restore --image-path /tmp/checkpoint --work-path /tmp/checkpoint looper
 +
</pre>
 +
 
 +
Show running containers:
 +
 
 +
<pre>
 +
sudo runc list
 +
sudo runc state looper
 +
</pre>
 +
 
 +
The following command can be used to terminate the running container:
 +
<pre>
 +
sudo runc kill looper KILL
 +
sudo runc delete looper
 +
</pre>
571

edits