<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Containers on Wimpy's World</title><link>https://blog.wimpys.world/tags/containers/</link><description>Recent content in Containers on Wimpy's World</description><generator>Hugo -- gohugo.io</generator><language>en-gb</language><managingEditor>martin@wimpress.com (Martin Wimpress)</managingEditor><webMaster>martin@wimpress.com (Martin Wimpress)</webMaster><lastBuildDate>Tue, 15 Apr 2014 02:44:11 +0000</lastBuildDate><atom:link href="https://blog.wimpys.world/tags/containers/rss.xml" rel="self" type="application/rss+xml"/><item><title>LXC on Arch Linux</title><link>https://blog.wimpys.world/posts/lxc-on-arch-linux/</link><pubDate>Tue, 15 Apr 2014 02:44:11 +0000</pubDate><author>martin@wimpress.com (Martin Wimpress)</author><guid>https://wimpysworld.com/posts/lxc-on-arch-linux/</guid><description>&lt;p&gt;At some point last year I was experimenting with Linux Containers (LXC) on
Arch Linux. &lt;strong&gt;I never finished the blog post but somehow it was briefly published
and then unplublished&lt;/strong&gt;. I have no idea how accurate this blog post is but someone
did see it and bookmarked it. &lt;strong&gt;They recently emailed me to ask where the blog has
disappeared to, so here it is in all its unfinished glory&lt;/strong&gt;.&lt;/p&gt;
&lt;h1 id="install-lxc"&gt;Install LXC&lt;/h1&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo pacman -Syy --needed --noconfirm arch-install-scripts bridge-utils lxc netctl
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h1 id="netctl-bridge"&gt;netctl Bridge&lt;/h1&gt;
&lt;p&gt;The guest containers will connect to the LAN via a bridged network deviced.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo nano /etc/netctl/bridge
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Add the following.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nv"&gt;Description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;Bridge&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nv"&gt;Interface&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;br0
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nv"&gt;Connection&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;bridge
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nv"&gt;BindsToInterfaces&lt;/span&gt;&lt;span class="o"&gt;=(&lt;/span&gt;eth0&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nv"&gt;IP&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;dhcp
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;## sets forward delay time&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nv"&gt;FwdDelay&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;## sets max age of hello message&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;#MaxAge=10&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Enable and start the bridge.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo netctl &lt;span class="nb"&gt;enable&lt;/span&gt; bridge
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo netctl start bridge
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h1 id="creating-containers"&gt;Creating Containers&lt;/h1&gt;
&lt;p&gt;I&amp;rsquo;m only interested in running Arch Linux or Debian containers.&lt;/p&gt;
&lt;h2 id="container-configurations"&gt;Container Configurations&lt;/h2&gt;
&lt;p&gt;Each container should have a matching configuration file, they look something like this.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;lxc.arch = i686
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;lxc.utsname = myhostname
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;lxc.network.type = veth
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;lxc.network.flags = up
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;lxc.network.link = br0
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;lxc.network.ipv4 = 0.0.0.0
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;lxc.network.name = eth0
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;
&lt;li&gt;&lt;code&gt;lxc.arch&lt;/code&gt; Architecture for the container, valid options are &lt;code&gt;x86&lt;/code&gt;, &lt;code&gt;i686&lt;/code&gt;, &lt;code&gt;x86_64&lt;/code&gt;, &lt;code&gt;amd64&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;lxc.utsman&lt;/code&gt; Container name, should also be used when naming the configuration file&lt;/li&gt;
&lt;li&gt;&lt;code&gt;lxc_network.type&lt;/code&gt; Type of network virtualization to be used for the
container. The option &lt;code&gt;veth&lt;/code&gt; defines a peer network device. It is created
with one side assigned to the container and the other side is attached to a
bridge by the &lt;code&gt;lxc.network.link&lt;/code&gt; option.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;lxc_network.flags&lt;/code&gt; Network actions. The value &lt;code&gt;up&lt;/code&gt; in this case activates the network.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;lxc.network.link&lt;/code&gt; Host network interface to be used for the container.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;lxc.network.ipv4&lt;/code&gt; IPv4 address assigned to the virtualized interface. Use
the address 0.0.0.0 to make use of DHCP. Use &lt;code&gt;lxc.network.ipv6&lt;/code&gt; if you need
IPv6 support.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;lxc.network.name&lt;/code&gt; Dynamically allocated interface name. This option will
rename the interface in the container.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;More example files can be found in &lt;code&gt;/usr/share/doc/lxc/examples/&lt;/code&gt;.
Find details about all options via &lt;code&gt;man lxc.conf&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id="arch-linux"&gt;Arch Linux&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo lxc-create -t archlinux -n arch-01 -f ~/arch-01.conf -- --packages netctl
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I am unable to get DHCP to work for a Arch Linux LXC container, therefore
my dirty hack is to alway use a statis IP address in the &lt;code&gt;netctl&lt;/code&gt; profile. There
is also a bug (&lt;a href="https://bugs.archlinux.org/task/35715"&gt;#35715&lt;/a&gt;) was helpful in
narrowing down the problem, but wasn&amp;rsquo;t the solution in my case. Use
&lt;code&gt;/var/lib/lxc/CONTAIN_NAME/rootfs/etc/netctl/example/ethernet-static&lt;/code&gt; as a template.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo cp /var/lib/lxc/CONTAIN_NAME/rootfs/etc/netctl/example/ethernet-static /var/lib/lxc/CONTAIN_NAME/rootfs/etc/netctl/static
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Modify &lt;code&gt;/var/lib/lxc/CONTAIN_NAME/rootfs/etc/netctl/static&lt;/code&gt; accordingly. Now
create a hook, with the same name as the &lt;code&gt;netctl&lt;/code&gt; profile.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo nano /var/lib/lxc/CONTAIN_NAME/rootfs/etc/netctl/hooks/static
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Add the following.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="cp"&gt;#!/usr/bin/env bash
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="k"&gt;$(&lt;/span&gt;systemd-detect-virt&lt;span class="k"&gt;)&lt;/span&gt; !&lt;span class="o"&gt;=&lt;/span&gt; none &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nv"&gt;BindsToInterfaces&lt;/span&gt;&lt;span class="o"&gt;=()&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="nv"&gt;ForceConnect&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;yes
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Start the container and enable the &lt;code&gt;netctl&lt;/code&gt; profile.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;netctl &lt;span class="nb"&gt;enable&lt;/span&gt; static
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;netctl start static
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="debian-containers"&gt;Debian Containers.&lt;/h2&gt;
&lt;p&gt;Install &lt;code&gt;debobootstrap&lt;/code&gt; and &lt;code&gt;dpkg&lt;/code&gt; so that Debian containers can be created.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;packer -S --noedit dpkg debootstrap
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="squeeze"&gt;Squeeze&lt;/h3&gt;
&lt;p&gt;Create a Debian container, &lt;code&gt;squeeze&lt;/code&gt; is the default.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo lxc-create -t debian -n squeeze-01 -f ~/squeeze-01.conf
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Change the &lt;code&gt;root&lt;/code&gt; password.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;chroot /var/lib/lxc/squeeze/rootfs/ passwd
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="wheezy"&gt;Wheezy&lt;/h3&gt;
&lt;p&gt;Much the same as the Squeeze exaple above but use the following template.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/simonvanderveldt/lxc-debian-wheezy-template"&gt;https://github.com/simonvanderveldt/lxc-debian-wheezy-template&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id="using-containers"&gt;Using containers&lt;/h1&gt;
&lt;p&gt;Start a container&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo lxc-start -d -n CONTAINER_NAME
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Connect to the container and log in:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo lxc-console -n CONTAINER_NAME
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;To halt a container cleanly by the containers initv-system:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo lxc-halt -n CONTAINER_NAME
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Stop and remove your container always with the two steps:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo lxc-stop -n CONTAINER_NAME
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;sudo lxc-destroy -n CONTAINER_NAME
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 id="references"&gt;References&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://nurupoga.org/articles/archlinux-on-lxc-with-netctl/"&gt;http://nurupoga.org/articles/archlinux-on-lxc-with-netctl/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://bbs.archlinux.org/viewtopic.php?id=164753"&gt;https://bbs.archlinux.org/viewtopic.php?id=164753&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://andyortlieb.wordpress.com/2013/03/15/practical-use-of-lxc-in-arch-linux-in-march-of-2013/"&gt;http://andyortlieb.wordpress.com/2013/03/15/practical-use-of-lxc-in-arch-linux-in-march-of-2013/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://wiki.archlinux.org/index.php/Linux_Containers"&gt;https://wiki.archlinux.org/index.php/Linux_Containers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://wiki.archlinux.org/index.php/Lxc-systemd"&gt;https://wiki.archlinux.org/index.php/Lxc-systemd&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://wiki.archlinux.org/index.php/Netctl"&gt;https://wiki.archlinux.org/index.php/Netctl&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.suse.com/documentation/sles11/singlehtml/lxc_quickstart/lxc_quickstart.html"&gt;https://www.suse.com/documentation/sles11/singlehtml/lxc_quickstart/lxc_quickstart.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://wiki.gentoo.org/wiki/LXC"&gt;http://wiki.gentoo.org/wiki/LXC&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description><summary>A rough guide to running Debian containers on Arch Linux with LXC</summary></item></channel></rss>