<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>QEMU on Zwindler's Reflection</title><link>https://blog.zwindler.fr/en/tags/qemu/</link><description>Recent content in QEMU on Zwindler's Reflection</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>Licensed under CC BY-SA 4.0</copyright><lastBuildDate>Mon, 07 Nov 2022 06:30:00 +0200</lastBuildDate><atom:link href="https://blog.zwindler.fr/en/tags/qemu/index.xml" rel="self" type="application/rss+xml"/><item><title>Running Docker containers with Proxmox VE (and LXC)</title><link>https://blog.zwindler.fr/en/2022/11/07/running-docker-containers-with-proxmox-ve-and-lxc/</link><pubDate>Mon, 07 Nov 2022 06:30:00 +0200</pubDate><guid>https://blog.zwindler.fr/en/2022/11/07/running-docker-containers-with-proxmox-ve-and-lxc/</guid><description>&lt;img src="https://blog.zwindler.fr/2019/10/proxmox.webp" alt="Featured image of post Running Docker containers with Proxmox VE (and LXC)" /&gt;&lt;h2 id="introduction"&gt;Introduction
&lt;/h2&gt;&lt;p&gt;I found several tutorials to install Docker (engine) &lt;strong&gt;inside&lt;/strong&gt; an LXC container under Proxmox VE to then run Docker containers inside it. The problem is that you have to log &lt;strong&gt;into&lt;/strong&gt; the LXC container before you can interact with your Docker containers.&lt;/p&gt;
&lt;p&gt;You can also install Docker directly on Proxmox VE but it&amp;rsquo;s not really recommended and you don&amp;rsquo;t have the ease of use of LXC with Proxmox GUI.&lt;/p&gt;
&lt;p&gt;And actually, it turns out you can run Docker images &lt;strong&gt;as the OS&lt;/strong&gt; of an LXC container and thus have Docker controlled by Proxmox. So we won&amp;rsquo;t have 100% identical behavior to if you had done a &lt;code&gt;docker run&lt;/code&gt; on your machine.&lt;/p&gt;
&lt;p&gt;However, we&amp;rsquo;ll gain in exchange a container totally identical to your other LXC containers in your cluster (with all associated functions) but launched with a Docker image.&lt;/p&gt;
&lt;p&gt;But first I suggest we go back a bit before showing you how&amp;hellip;&lt;/p&gt;
&lt;h2 id="context"&gt;Context
&lt;/h2&gt;&lt;p&gt;You know, I&amp;rsquo;ve been doing Proxmox VE for a while. Proxmox VE is a great turnkey and production-ready distribution for server virtualization (it&amp;rsquo;s even hyperconverged if you enable the Ceph part).&lt;/p&gt;
&lt;p&gt;There are lots of little things I like about Proxmox VE, and one of them is that we can create Linux containers with LXC rather than QEMU virtual machines. &lt;a class="link" href="https://blog.zwindler.fr/2022/10/22/proxmox-tips-tricks/" &gt;I wrote an article to talk about it&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In use (except for specific kernel configuration), the LXC container behaves strictly identically to a VM in Proxmox, but for a fraction of the resources! We have an OS, we install applications on it, like a VM.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://blog.zwindler.fr/2022/11/nginx.avif"
loading="lazy"
&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;An nginx frontend for several applications. The complete LXC container only consumes a few MB&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Admittedly it&amp;rsquo;s much less isolated than a real VM (because it&amp;rsquo;s a container, we&amp;rsquo;re isolated from other processes, but we run on the hypervisor&amp;rsquo;s kernel directly).&lt;/p&gt;
&lt;p&gt;But with so few resource needs, I can host many small applications in different contexts with very small physical machines (Atom 4GB RAM at €6 per month at OneProviders) which would be impossible with a real VM.&lt;/p&gt;
&lt;h2 id="its-good-but-not-enough"&gt;It&amp;rsquo;s good, but not enough
&lt;/h2&gt;&lt;p&gt;However, LXC is not the most known/hyped containerization technology. For years on the forum, whenever people ask for Docker support in Proxmox VE, they get sent away. Not always very nicely either&amp;hellip;&lt;/p&gt;
&lt;p&gt;Yet, there are several reasons to want to run Docker containers on your Proxmox infrastructure:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;First, Docker isn&amp;rsquo;t as much stateless and/or ephemeral workloads as we think. Many containerized applications would have their place on a virtualization cluster.&lt;/li&gt;
&lt;li&gt;Then because many software vendors have become lazy. Some no longer manage installation processes (or only on one OS) and just provide a Docker image that they maintain up to date.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So we have to settle for VMs in Proxmox to run Docker containers (see my point at the beginning).&lt;/p&gt;
&lt;h2 id="lxc-supports-oci-images"&gt;LXC supports OCI images
&lt;/h2&gt;&lt;p&gt;Plot twist. A few days ago, I discovered that LXC, Proxmox VE&amp;rsquo;s containerization engine, was compatible with the OCI format.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a class="link" href="https://www.buzzwrd.me/index.php/2021/03/10/creating-lxc-containers-from-docker-and-oci-images/" target="_blank" rel="noopener"
&gt;buzzwrd.me - Creating LXC containers from docker and OCI images&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For those who don&amp;rsquo;t know OCI, it&amp;rsquo;s an organization aiming to create a standard to unify the way containers are stored.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The Open Container Initiative is an open governance structure for the express purpose of creating open industry standards around container formats and runtimes.
&lt;a class="link" href="https://opencontainers.org/" target="_blank" rel="noopener"
&gt;opencontainers.org/&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;And Docker respects this format: we can therefore theoretically run from LXC containers whose base image is a Docker image.&lt;/p&gt;
&lt;h2 id="so-when-do-we-start"&gt;So, when do we start?
&lt;/h2&gt;&lt;p&gt;Disclaimer: what follows is tinkering. Nothing is supported and I don&amp;rsquo;t recommend it in production. There are also likely limitations (especially regarding storage).&lt;/p&gt;
&lt;p&gt;First, some dependencies are missing for LXC&amp;rsquo;s OCI function to be usable under Proxmox VE:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;sudo apt install skopeo umoci jq
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Then, by default, LXC containers attach to a Linux bridge called &lt;code&gt;lxcbr0&lt;/code&gt;. However this bridge probably doesn&amp;rsquo;t exist on your Proxmox VE installation (not installed by default).&lt;/p&gt;
&lt;p&gt;In &lt;em&gt;quick and dirty&lt;/em&gt;, we can just replace the default name, although ideally we should find the flag in the CLI to change the bridge. Depending on how you configured the network in your Proxmox VE server, you&amp;rsquo;ll probably use &lt;code&gt;vmbr0&lt;/code&gt; or &lt;code&gt;vmbr1&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;sed -i &amp;#39;s/lxcbr0/vmbr1/g&amp;#39; /etc/lxc/default.conf
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now that we have everything, we can run our LXC containers from docker images. Here I&amp;rsquo;m running the official &lt;code&gt;alpine:latest&lt;/code&gt; image, but I could have taken any other:&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;lxc-create 500 -t oci -- --url docker://alpine:latest
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I created a container called &amp;ldquo;500&amp;rdquo; (because VMs and LXC containers in proxmox VE are called with numbers). The image is downloaded then the container created:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://blog.zwindler.fr/2022/11/lxc_docker_pull.avif"
loading="lazy"
&gt;&lt;/p&gt;
&lt;p&gt;We can now start it (with &lt;code&gt;lxc-execute&lt;/code&gt; we run the container and open a prompt directly inside it, but we also have &lt;code&gt;lxc-start&lt;/code&gt; and &lt;code&gt;lxc-attach&lt;/code&gt;)&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;lxc-execute 500
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;img src="https://blog.zwindler.fr/2022/11/alpine.avif"
loading="lazy"
&gt;&lt;/p&gt;
&lt;p&gt;As is, Proxmox VE doesn&amp;rsquo;t know our container exists and it won&amp;rsquo;t appear in the UI. But it works ;-).&lt;/p&gt;
&lt;h2 id="bonus"&gt;Bonus
&lt;/h2&gt;&lt;p&gt;We can even cheat and make Proxmox believe it&amp;rsquo;s an LXC container it created itself by creating a &lt;code&gt;500.conf&lt;/code&gt; file, in the &lt;code&gt;/etc/pve/lxc/&lt;/code&gt; folder&lt;/p&gt;
&lt;p&gt;The only mandatory fields are the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;arch (amd64 unless you&amp;rsquo;re on ARM)&lt;/li&gt;
&lt;li&gt;cores (the CPU limit to impose on the container)&lt;/li&gt;
&lt;li&gt;hostname&lt;/li&gt;
&lt;li&gt;memory (the RAM limit to impose on the container)&lt;/li&gt;
&lt;li&gt;ostype&lt;/li&gt;
&lt;li&gt;rootfs&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src="https://blog.zwindler.fr/2022/11/lxc_config.avif"
loading="lazy"
&gt;&lt;/p&gt;
&lt;p&gt;Once the file is created, the container automatically appears in the host&amp;rsquo;s VM list. We can start it and it works :)&lt;/p&gt;
&lt;p&gt;&lt;img src="https://blog.zwindler.fr/2022/11/docker_lxc_running.avif"
loading="lazy"
&gt;&lt;/p&gt;
&lt;p&gt;The container can be started, stopped, etc. All from the Proxmox VE GUI :)&lt;/p&gt;
&lt;p&gt;Have fun!&lt;/p&gt;
&lt;h2 id="source"&gt;Source
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;&lt;a class="link" href="https://pve.proxmox.com/wiki/Linux_Container" target="_blank" rel="noopener"
&gt;Proxmox VE - Linux Container&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="link" href="https://thehomelab.wiki/books/promox-ve/page/setup-and-install-docker-in-a-promox-7-lxc-conainer" target="_blank" rel="noopener"
&gt;Setup and Install Docker in a Promox 7 LXC Conainer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="link" href="https://www.buzzwrd.me/index.php/2021/03/10/creating-lxc-containers-from-docker-and-oci-images/" target="_blank" rel="noopener"
&gt;buzzwrd.me - Creating LXC containers from docker and OCI images&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description></item></channel></rss>