<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>nspawn &#8211; FU-BAR</title>
	<atom:link href="/tag/nspawn/feed/" rel="self" type="application/rss+xml" />
	<link>/</link>
	<description>Fucked Up Beyond All Recognition</description>
	<lastBuildDate>Sat, 07 Jan 2017 21:08:31 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>/wp-content/uploads/2020/07/cropped-eu-header-20200715-2-32x32.png</url>
	<title>nspawn &#8211; FU-BAR</title>
	<link>/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Simple experiment with systemd-nspawn containers</title>
		<link>/2017/01/07/systemd-nspawn-experiment/</link>
		
		<dc:creator><![CDATA[Rui Seabra]]></dc:creator>
		<pubDate>Sat, 07 Jan 2017 18:54:07 +0000</pubDate>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[Free Software]]></category>
		<category><![CDATA[nspawn]]></category>
		<category><![CDATA[systemd]]></category>
		<guid isPermaLink="false">/?p=2566</guid>

					<description><![CDATA[For this test I used Fedora 25. Your mileage might vary in other operating systems, some things may be the same, some may not be. WARNING: you&#8217;ll need to disable selinux so to me this was merely an interesting experiment and it lead to increasing my knowledge, specially in relation to selinux + containers. Bad &#8230; <p class="link-more"><a href="/2017/01/07/systemd-nspawn-experiment/" class="more-link">Continue reading<span class="screen-reader-text"> "Simple experiment with systemd-nspawn containers"</span></a></p>]]></description>
										<content:encoded><![CDATA[<p>For this test I used Fedora 25. Your mileage might vary in other operating systems, some things may be the same, some may not be.</p>
<p><strong>WARNING</strong>: you&#8217;ll need to disable selinux so to me this was merely an interesting experiment and it lead to increasing my knowledge, specially in relation to selinux + containers. Bad mix, no security, containers don&#8217;t contain, etc.</p>
<p><strong>Many thanks</strong> to the nice people from #fedora and #selinux that graciously lent their time to help me when I was trying to use nspawn with selinux enabled. With their help, specially Grift from #selinux, we were actually able to run it, but only in a way I&#8217;m so uncomfortable with that I ultimately considered this experiment to  be a #fail as I&#8217;m definitely not going to use them like that any time soon: there&#8217;s still a lot of work to do in order to run containers with some security. I hope the Docker infatuation leads to an universal solution towards security + containers from the good engineers at Red Hat and others involved in that work.</p>
<p>But it certainly was a success in terms of contributing to more experience beyond a quickly expiring benefit of familiarity with OpenVZ.</p>
<p>Enough words, here&#8217;s how simply it was&#8230;</p>
<p><strong>Firstly</strong>, let&#8217;s setup a template from which we&#8217;re going to copy to new instances. As I&#8217;m using Fedora 25, I used DNF&#8217;s capability to install under a directory:</p>
<pre>dnf --releasever=25 \
 --installroot=/var/lib/machines/template-fedora-25 \
 -y install systemd passwd dnf fedora-release \
 iproute less vi procps-ng tcpdump iputils</pre>
<p>You&#8217;ll only need the first three lines, though, the fourth was just a few more packaged I preferred to have in my template.</p>
<p><strong>Secondly</strong>, you&#8217;ll probably like to do further customization in your template, so you&#8217;ll enter your container just like it was (well, is) an enhanced chroot:</p>
<pre>cd /var/lib/machines
systemd-nspawn -D template-fedora-25</pre>
<p>Now we have a console, and the sky is the limit for what you can setup, like for instance defining a default pasword for root with <strong>passwd</strong> (but maybe you&#8217;ll not want to do this in a production environment).</p>
<p>For some weird reason, passwd constantly failed manipulating authentication tokens, but I solved it quickly by merely reinstalling passwd (<em>dnf -y reinstall passwd</em>). Meh&#8230;</p>
<p>I also ran dnf -y clean all before exiting the container in order to clean up unnecessary space wasted with package meta data that will be expired quickly.</p>
<p>When you&#8217;re done customizing, exit the container with <strong> ctrl + ]]]</strong> in about a second.</p>
<p><strong>Finally</strong>, we&#8217;re ready to preserve the template:</p>
<pre>cd template-fedora-25
tar --selinux --acls --xattrs czvf \
    ../$(basename $( pwd ) )-$(date +%Y%m%d).tar.gz .
cd ..</pre>
<p><strong>We&#8217;re now ready</strong> to create a test container and launch it in the background:</p>
<pre>mkdir test
cd test
tar --selinux --acls -xattrs xzvf \
    ../template-fedora-25-20170701.tar.gz
cd ..
machinectl start test</pre>
<p>This container will probably not be able to run services exposed outside without help but you can login into its console with <strong>machinectl login test</strong></p>
<p>You&#8217;ll also have <em>automagic</em> name resolution from your host computer to the containers it runs if you change the hosts entry in /etc/nsswitch.conf placing <strong>mymachines</strong> between files and dns (or as you see fit if otherwise in your setup):</p>
<pre>hosts: files mymachines dns myhostname</pre>
<p>If you had enable ssh in your container, you&#8217;d be able to do <strong>ssh test</strong> from the host machine. Or access a web server you installed in it. Who knows.</p>
<p>As you saw, despite a lot of words trying to explain every step of the way, it&#8217;s excruciatingly simple.</p>
<p>The next article (<a href="/2017/01/07/systemd-networkd-resolved/">Simple experiment with systemd-networkd and systemd-resolved</a>) expands this example with a bridge in the host machine in order to allow your containers to talk directly with the external world.</p>
<p>Happy hacking!</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
