<p>I want to be able to perform something like <code>docker commit</code> on a container running inside a Kubernetes pod.</p>

<p>Volume snapshots do not meet my criteria because I want to snapshot the complete state of the container, not just the data mounted under some path.</p>

<p>I need this because I provide (trusted) users root access to containers and I want to be able to provide a way to roll the containers back without losing any packages they have installed (or any other changes they have made) before the last snapshot.</p>

<p>It appears <a href="https://github.com/kubernetes/kubernetes/issues/14561" rel="noreferrer">a related feature request</a> was made but nothing came of it.</p>

<p>I am using Google Kubernetes Engine but I am prepared to migrate to another provider that easily supports this.</p>

neprune
<p>Run the bash shell inside a container named guest:</p>

<pre><code>[root@host ~]# docker run -i -t --name guest oraclelinux:6.6 /bin/bash
[root@guest ~]#
</code></pre>

<p>If you use a web proxy, edit the yum configuration on the guest as described in the <a href="http://docs.oracle.com/cd/E52668_01/E54669/html/ol7-proxy-config.html" rel="nofollow noreferrer">Oracle Linux Administrator's Guide for Release 7</a>.</p>

<p>Install the httpd package:    </p>

<pre><code>[root@guest ~]# yum install httpd
</code></pre>

<p>If required, create the web content to be displayed under the <code>/var/www/html</code> directory hierarchy on the guest.</p>

<p>Exit the guest by using the docker stop command on the host:</p>

<pre><code>[root@host ~]# docker stop guest
guest
</code></pre>

<p>Create the image <code>mymod/httpd</code> with the tag <code>v1</code> using the ID of the container that you stopped:</p>

<pre><code>[root@host ~]# docker commit -m "ol6 + httpd" -a "A N Other" \
`docker ps -l -q` mymod/httpd:v1
8594abec905e6374db51bed1bfb208804cfb60d96b285efb897db581a01676e9
</code></pre>

<p>Use the <code>-m</code> and <code>-a</code> options to document the image and its author. The command returns the full version of the new image's ID.</p>

<p>If you use the docker images command, the new image now appears in the list:   </p>

<pre><code>  [root@host ~]# docker images
    REPOSITORY    TAG         IMAGE ID       CREATED       VIRTUAL SIZE
    mymod/httpd   v1          8594abec905e   2 minutes ago 938.5 MB
    oraclelinux   6           9ac13076d2b5   5 days ago    319.4 MB
    oraclelinux   6.6         9ac13076d2b5   5 days ago    319.4 MB
    oraclelinux   latest      073ded22ac0f   5 days ago    265.2 MB
    oraclelinux   7           073ded22ac0f   5 days ago    265.2 MB
    oraclelinux   7.0         073ded22ac0f   5 days ago    265.2 MB
</code></pre>

<p>Remove the container named guest.</p>

<pre><code>    # docker rm guest
    guest
</code></pre>

<p>You can now use the new image to create a container that works as a web server, for example:</p>

<pre><code> # docker run -d --name newguest -p 8080:80 mymod/httpd:v1 /usr/sbin/httpd -D FOREGROUND
 7afbbefec5191f632e149f85ae10ed0ba88f1c545daad18cb930e575ef6a3e63
</code></pre>
