<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.alpinelinux.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Mike.edmister</id>
	<title>Alpine Linux - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.alpinelinux.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Mike.edmister"/>
	<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/wiki/Special:Contributions/Mike.edmister"/>
	<updated>2026-04-30T01:27:11Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.40.0</generator>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=LXC&amp;diff=15699</id>
		<title>LXC</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=LXC&amp;diff=15699"/>
		<updated>2019-02-04T22:22:59Z</updated>

		<summary type="html">&lt;p&gt;Mike.edmister: /* Prepare network on host */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[https://linuxcontainers.org/ Linux Containers (LXC)] provides containers similar BSD Jails, Linux VServer and Solaris Zones. It gives the impression of virtualization, but shares the kernel and resources with the &amp;quot;host&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
Install the required packages:&lt;br /&gt;
{{Cmd|apk add lxc bridge}}&lt;br /&gt;
&lt;br /&gt;
If you want to create containers other than alpine you will need lxc-templates:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk add lxc-templates}}&lt;br /&gt;
&lt;br /&gt;
== Upgrading from 2.x ==&lt;br /&gt;
&lt;br /&gt;
Since Alpine 3.9 we ship LXC version 3.1.&lt;br /&gt;
LXC 3.x has major changes which will/can break your current setup.&lt;br /&gt;
LXC 3.x will NOT ship with legacy container templates. Check your current container configs to see if you have any includes pointing to files that don&#039;t exist (shipped by legacy templates).&lt;br /&gt;
For example if you use Alpine containers created with the alpine template you will need to install:&lt;br /&gt;
&lt;br /&gt;
 apk add lxc-templates-legacy-alpine&lt;br /&gt;
&lt;br /&gt;
Also make sure you convert your LXC config files to the new 2.x format (this is now required).&lt;br /&gt;
&lt;br /&gt;
 lxc-update-config -c /var/lib/lxc/container-name/config&lt;br /&gt;
&lt;br /&gt;
Make sure you have removed &#039;&#039;&#039;cgroup_enable&#039;&#039;&#039; from your cmdline as this will fail to mount cgroups and fail LXC service.&lt;br /&gt;
&lt;br /&gt;
== Prepare network on host ==&lt;br /&gt;
Set up a [[bridge]] on the host. Example &#039;&#039;/etc/network/interfaces&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
auto br0&lt;br /&gt;
iface br0 inet dhcp&lt;br /&gt;
    bridge-ports eth0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a network configuration template for the guests, &#039;&#039;/etc/lxc/default.conf&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lxc.net.0.type = veth&lt;br /&gt;
lxc.net.0.link = br0&lt;br /&gt;
lxc.net.0.flags = up&lt;br /&gt;
lxc.net.0.hwaddr = fe:xx:xx:xx:xx:xx&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Grsecurity restrictions ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE&#039;&#039;&#039;: since alpine 3.8 we no longer ship grsecurity and it should not be used in lxc setup.&lt;br /&gt;
&lt;br /&gt;
Some restrictions will be applied when using a grsecurity kernel (Alpine Linux default kernel).&lt;br /&gt;
The most notable is the use of lxc-attach which will not be allowed because of GRKERNSEC_CHROOT_CAPS.&lt;br /&gt;
To solve this we will have to disable this grsec restriction by creating a sysctl profile for lxc.&lt;br /&gt;
Create the following file &#039;&#039;/etc/sysctl.d/10-lxc.conf&#039;&#039; and add:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
kernel.grsecurity.chroot_caps = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are a few other restrictions that can prevent proper container functionality. &lt;br /&gt;
When things do not work as expected always check the kernel log with dmesg to see if grsec prevented things from happening.&lt;br /&gt;
&lt;br /&gt;
Other possible restrictions are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
kernel.grsecurity.chroot_deny_chroot = 0&lt;br /&gt;
kernel.grsecurity.chroot_deny_mount = 0&lt;br /&gt;
kernel.grsecurity.chroot_deny_mknod = 0&lt;br /&gt;
kernel.grsecurity.chroot_deny_chmod = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you finished creating your new sysctl profile you can apply it by restarting sysctl service&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rc-service sysctl restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: Always consult the [https://en.wikibooks.org/wiki/Grsecurity/Appendix/Grsecurity_and_PaX_Configuration_Options Grsecurity documentation] before applying these settings.&lt;br /&gt;
&lt;br /&gt;
== Create a guest ==&lt;br /&gt;
&lt;br /&gt;
=== Alpine Template ===&lt;br /&gt;
&lt;br /&gt;
{{Cmd|lxc-create -n guest1 -f /etc/lxc/lxc.conf -t alpine}}&lt;br /&gt;
&lt;br /&gt;
This will create a &#039;&#039;/var/lib/lxc/guest1&#039;&#039; directory with a &#039;&#039;config&#039;&#039; file and a &#039;&#039;rootfs&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
Note that by default alpine template &#039;&#039;&#039;does not have networking service on&#039;&#039;&#039;, you will need to add it using lxc-console&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If running on x86_64 architecture, it is possible to create a 32bit guest:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|lxc-create -n guest1 -f /etc/lxc/lxc.conf -t alpine -- --arch x86}}&lt;br /&gt;
&lt;br /&gt;
=== Debian template ===&lt;br /&gt;
&lt;br /&gt;
In order to create a debian template container you will need to install some packages:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk add debootstrap rsync}}&lt;br /&gt;
&lt;br /&gt;
Also you will need to turn off some grsecurity chroot options otherwise the debootstrap will fail:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|echo 0 &amp;gt; /proc/sys/kernel/grsecurity/chroot_caps&lt;br /&gt;
echo 0 &amp;gt; /proc/sys/kernel/grsecurity/chroot_deny_chroot&lt;br /&gt;
echo 0 &amp;gt; /proc/sys/kernel/grsecurity/chroot_deny_mount&lt;br /&gt;
echo 0 &amp;gt; /proc/sys/kernel/grsecurity/chroot_deny_mknod&lt;br /&gt;
echo 0 &amp;gt; /proc/sys/kernel/grsecurity/chroot_deny_chmod&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Please remember to turn them back on, or just simply reboot the system.&lt;br /&gt;
&lt;br /&gt;
Now you can run:&lt;br /&gt;
{{Cmd|SUITE{{=}}wheezy lxc-create -n guest1 -f /etc/lxc/lxc.conf -t debian}}&lt;br /&gt;
&lt;br /&gt;
=== Ubuntu template ===&lt;br /&gt;
&lt;br /&gt;
In order to create an ubuntu template container you will need to turn off some grsecurity chroot options:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|echo 0 &amp;gt; /proc/sys/kernel/grsecurity/chroot_caps&lt;br /&gt;
echo 0 &amp;gt; /proc/sys/kernel/grsecurity/chroot_deny_chroot&lt;br /&gt;
echo 0 &amp;gt; /proc/sys/kernel/grsecurity/chroot_deny_mount&lt;br /&gt;
echo 0 &amp;gt; /proc/sys/kernel/grsecurity/chroot_deny_mknod&lt;br /&gt;
echo 0 &amp;gt; /proc/sys/kernel/grsecurity/chroot_deny_chmod&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Please remember to turn them back on, or just simply reboot the system.&lt;br /&gt;
&lt;br /&gt;
Now you can run (replace %MIRROR% with the actual hostname, for example: http://us.archive.ubuntu.com/ubuntu/)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
lxc-create -n guest2 -f /etc/lxc/default.conf -t ubuntu -- -r xenial -a amd64 -u user --password secretpassword --mirror $MIRROR&lt;br /&gt;
&lt;br /&gt;
=== Unprivileged LXC images (Debian / Ubuntu / Centos etc..) ===&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk add gnupg xz&lt;br /&gt;
lxc-create -n container-name -t download}}&lt;br /&gt;
&amp;amp; choose the Distribution | Release | Architecture.&lt;br /&gt;
&lt;br /&gt;
To be able to login to a Debian container you currently need to:&lt;br /&gt;
{{Cmd|rm /lib/systemd/system/container-getty\@.service}}&lt;br /&gt;
&lt;br /&gt;
You can also [http://without-systemd.org/wiki/index.php/How_to_remove_systemd_from_a_Debian_jessie/sid_installationers remove Systemd from the container].&lt;br /&gt;
&lt;br /&gt;
== Starting/Stopping the guest ==&lt;br /&gt;
Create a symlink to the &#039;&#039;/etc/init.d/lxc&#039;&#039; script for your guest.&lt;br /&gt;
{{Cmd|ln -s lxc /etc/init.d/lxc.guest1}}&lt;br /&gt;
&lt;br /&gt;
You can start your guest with:&lt;br /&gt;
{{Cmd|/etc/init.d/lxc.guest1 start}}&lt;br /&gt;
&lt;br /&gt;
Stop it with:&lt;br /&gt;
{{Cmd|/etc/init.d/lxc.guest1 stop}}&lt;br /&gt;
&lt;br /&gt;
Make it autostart on boot up with:&lt;br /&gt;
{{Cmd| rc-update add lxc.guest1}}&lt;br /&gt;
&lt;br /&gt;
You can also add to the container config: &amp;lt;code&amp;gt;lxc.start.auto = 1&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp; {{Cmd|rc-update add lxc}}&lt;br /&gt;
&lt;br /&gt;
to autostart containers by the lxc service only.&lt;br /&gt;
&lt;br /&gt;
== Connecting to the guest ==&lt;br /&gt;
By default sshd is not installed, so you will have to attach to the container or connect to the virtual console. This is done with:&lt;br /&gt;
&lt;br /&gt;
=== Attach to container ===&lt;br /&gt;
&lt;br /&gt;
{{Cmd|lxc-attach -n guest1}}&lt;br /&gt;
&lt;br /&gt;
Just type exit to detach the container again (please do check the grsec notes above)&lt;br /&gt;
&lt;br /&gt;
=== Connect to virtual console ===&lt;br /&gt;
&lt;br /&gt;
{{Cmd|lxc-console -n guest1}}&lt;br /&gt;
&lt;br /&gt;
To disconnect from it, press {{key|Ctrl}}+{{key|a}} {{key|q}}&lt;br /&gt;
&lt;br /&gt;
== Deleting a guest ==&lt;br /&gt;
Make sure the guest is stopped and run:&lt;br /&gt;
{{Cmd|lxc-destroy -n guest1}}&lt;br /&gt;
This will erase everything, without asking any questions. It is equivalent to: {{Cmd|rm -r /var/lib/lxc/guest1}}&lt;br /&gt;
&lt;br /&gt;
== Advanced ==&lt;br /&gt;
&lt;br /&gt;
=== Creating a LXC container without modifying your network interfaces ===&lt;br /&gt;
&lt;br /&gt;
The problem with bridging is that the interface you bridge gets replaced with your new bridge interface.&lt;br /&gt;
That is to say that say you have an interface eth0 that you want to bridge, your eth0 interface gets replaced with the br0 interface that you create. It also means that the interface you use needs to be placed into promiscuous mode to catch all the traffic that could de destined to the other side of the bridge, which again may not be what you want.&lt;br /&gt;
&lt;br /&gt;
The solution is to create a dummy network interface, bridge that, and set up NAT so that traffic out of your bridge interface gets pushed through the interface of your choice.&lt;br /&gt;
&lt;br /&gt;
So, first, lets create that dummy interface (thanks to ncopa for talking me out of macvlan and pointing out the dummy interface kernel module)&lt;br /&gt;
&lt;br /&gt;
{{Cmd|modprobe dummy}}&lt;br /&gt;
&lt;br /&gt;
This will create a dummy interface called dummy0 on your host. To create this interface on every boot, you may need to create a /etc/modprobe.d/dummy.conf with:&lt;br /&gt;
{{Cmd |# Load dummy.ko at boot&lt;br /&gt;
dummy }}&lt;br /&gt;
&lt;br /&gt;
Now we will create a bridge called br0&lt;br /&gt;
&lt;br /&gt;
{{Cmd |brctl addbr br0&lt;br /&gt;
brctl setfd br0 0 }}&lt;br /&gt;
&lt;br /&gt;
and then make that dummy interface one end of the bridge&lt;br /&gt;
&lt;br /&gt;
{{Cmd | brctl addif br0 dummy0 }}&lt;br /&gt;
&lt;br /&gt;
Next, let&#039;s give that bridged interface a reason to exists&lt;br /&gt;
&lt;br /&gt;
{{ Cmd | ifconfig br0 192.168.1.1 netmask 255.255.255.0 up}}&lt;br /&gt;
&lt;br /&gt;
Create a file for your container, let&#039;s say /etc/lxc/bridgenat.conf, with the following settings.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lxc.net.0.type = veth&lt;br /&gt;
lxc.net.0.flags = up&lt;br /&gt;
lxc.net.0.link = br0&lt;br /&gt;
lxc.net.0.name = eth1&lt;br /&gt;
lxc.net.0.ipv4.address = 192.168.1.2/24 192.168.1.255&lt;br /&gt;
lxc.net.0.ipv4.gateway = 192.168.1.1&lt;br /&gt;
lxc.net.0.veth.pair = veth-if-0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and build your container with that file&lt;br /&gt;
&lt;br /&gt;
{{ Cmd | lxc-create -n alpine -f /etc/lxc/bridgenat.conf -t alpine }}&lt;br /&gt;
&lt;br /&gt;
You should now be able to ping your container from your hosts, and your host from your container.&lt;br /&gt;
&lt;br /&gt;
Your container needs to know where to push traffic that isn&#039;t within it&#039;s subnet. To do so, we tell the container to route through the bridge interface br0&lt;br /&gt;
From inside the container run&lt;br /&gt;
&lt;br /&gt;
{{ Cmd | route add default gw 192.168.1.1 }}&lt;br /&gt;
&lt;br /&gt;
The next step is you push the traffic coming from your private subnet over br0 out through your internet facing interface, or any interface you chose&lt;br /&gt;
&lt;br /&gt;
We are messing with your IP tables here, so make sure these settings don&#039;t conflict with anything you may have already set up, obviously.&lt;br /&gt;
&lt;br /&gt;
Say eth0 was your internet facing network interface, and br0 is the name of the bridge you made earlier, we&#039;d do this:&lt;br /&gt;
&lt;br /&gt;
{{ Cmd | echo 1 &amp;gt; /proc/sys/net/ipv4/ip_forward&lt;br /&gt;
iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE&lt;br /&gt;
iptables --append FORWARD --in-interface br0 -j ACCEPT&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Now you should be able to route through your bridge interface to the internet facing interface of your host from your container, just like at home!&lt;br /&gt;
&lt;br /&gt;
You could also have a dhcp server running on your host, and set it up to give IP addresses from your private subnet to any container that requests it, and then have one template for multiple alpine LXC containers, perfect for alpine development :)&lt;br /&gt;
&lt;br /&gt;
=== Using static IP ===&lt;br /&gt;
&lt;br /&gt;
If you&#039;re using static IP, you need to configure this properly on guest&#039;s /etc/network/interfaces. To stay on the above example, modify &#039;&#039;/var/lib/lxc/guest1/rootfs/etc/network/interfaces&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
from&lt;br /&gt;
&lt;br /&gt;
 #auto lo&lt;br /&gt;
     iface lo inet loopback&lt;br /&gt;
 auto eth0&lt;br /&gt;
     iface eth0 inet &#039;&#039;&#039;dhcp&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
to &lt;br /&gt;
&lt;br /&gt;
 #auto lo&lt;br /&gt;
     iface lo inet loopback&lt;br /&gt;
 auto eth0&lt;br /&gt;
     iface eth0 inet &#039;&#039;&#039;static&#039;&#039;&#039;&lt;br /&gt;
     address &amp;lt;lxc-container-ip&amp;gt;   # IP which the lxc container should use&lt;br /&gt;
     gateway &amp;lt;gateway-ip&amp;gt;         # IP of gateway to use, mostly same as on lxc-host&lt;br /&gt;
     netmask &amp;lt;netmask&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== mem and swap ===&lt;br /&gt;
&lt;br /&gt;
{{Cmd|vim /boot/extlinux.conf}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|&lt;br /&gt;
  APPEND initrd{{=}}initramfs-3.10.13-1-grsec root{{=}}UUID{{=}}7cd8789f-5659-40f8-9548-ae8f89c918ab modules{{=}}sd-mod,usb-storage,ext4 quiet cgroup_enable{{=}}memory swapaccount{{=}}1&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== checkconfig ===&lt;br /&gt;
{{Cmd|lxc-checkconfig}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|&lt;br /&gt;
Kernel configuration not found at /proc/config.gz; searching...&lt;br /&gt;
Kernel configuration found at /boot/config-3.10.13-1-grsec&lt;br /&gt;
--- Namespaces ---&lt;br /&gt;
Namespaces: enabled&lt;br /&gt;
Utsname namespace: enabled&lt;br /&gt;
Ipc namespace: enabled&lt;br /&gt;
Pid namespace: enabled&lt;br /&gt;
User namespace: missing&lt;br /&gt;
Network namespace: enabled&lt;br /&gt;
Multiple /dev/pts instances: enabled&lt;br /&gt;
&lt;br /&gt;
--- Control groups ---&lt;br /&gt;
Cgroup: enabled&lt;br /&gt;
Cgroup clone_children flag: enabled&lt;br /&gt;
Cgroup device: enabled&lt;br /&gt;
Cgroup sched: enabled&lt;br /&gt;
Cgroup cpu account: enabled&lt;br /&gt;
Cgroup memory controller: missing&lt;br /&gt;
Cgroup cpuset: enabled&lt;br /&gt;
&lt;br /&gt;
--- Misc ---&lt;br /&gt;
Veth pair device: enabled&lt;br /&gt;
Macvlan: enabled&lt;br /&gt;
Vlan: enabled&lt;br /&gt;
File capabilities: enabled&lt;br /&gt;
&lt;br /&gt;
Note : Before booting a new kernel, you can check its configuration&lt;br /&gt;
usage : CONFIG{{=}}/path/to/config /usr/bin/lxc-checkconfig&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== VirtualBox ===&lt;br /&gt;
&lt;br /&gt;
In order for network to work on containers you need to set &amp;quot;Promiscuous Mode&amp;quot; to &amp;quot;Allow All&amp;quot; in VirtualBox settings for the network adapter.&lt;br /&gt;
&lt;br /&gt;
[[File:VirtualBoxNetworkAdapter.jpg]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Virtualization]]&lt;br /&gt;
&lt;br /&gt;
=== postgreSQL ===&lt;br /&gt;
&lt;br /&gt;
Inside the container run: {{Cmd|chmod go+w /dev/null}} to fix {{Cmd|rc-service postgresql start}}&lt;br /&gt;
&lt;br /&gt;
=== openVPN ===&lt;br /&gt;
&lt;br /&gt;
see [[Setting_up_a_OpenVPN_server#openVPN_and_LXC]]&lt;br /&gt;
&lt;br /&gt;
== LXC 1.0 Additional information ==&lt;br /&gt;
&lt;br /&gt;
Some info regarding new features in LXC 1.0&lt;br /&gt;
 &lt;br /&gt;
https://www.stgraber.org/2013/12/20/lxc-1-0-blog-post-series/&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Howto-lxc-simple]]&lt;/div&gt;</summary>
		<author><name>Mike.edmister</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=LXC&amp;diff=15698</id>
		<title>LXC</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=LXC&amp;diff=15698"/>
		<updated>2019-02-04T22:21:59Z</updated>

		<summary type="html">&lt;p&gt;Mike.edmister: /* Creating a LXC container without modifying your network interfaces */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[https://linuxcontainers.org/ Linux Containers (LXC)] provides containers similar BSD Jails, Linux VServer and Solaris Zones. It gives the impression of virtualization, but shares the kernel and resources with the &amp;quot;host&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
Install the required packages:&lt;br /&gt;
{{Cmd|apk add lxc bridge}}&lt;br /&gt;
&lt;br /&gt;
If you want to create containers other than alpine you will need lxc-templates:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk add lxc-templates}}&lt;br /&gt;
&lt;br /&gt;
== Upgrading from 2.x ==&lt;br /&gt;
&lt;br /&gt;
Since Alpine 3.9 we ship LXC version 3.1.&lt;br /&gt;
LXC 3.x has major changes which will/can break your current setup.&lt;br /&gt;
LXC 3.x will NOT ship with legacy container templates. Check your current container configs to see if you have any includes pointing to files that don&#039;t exist (shipped by legacy templates).&lt;br /&gt;
For example if you use Alpine containers created with the alpine template you will need to install:&lt;br /&gt;
&lt;br /&gt;
 apk add lxc-templates-legacy-alpine&lt;br /&gt;
&lt;br /&gt;
Also make sure you convert your LXC config files to the new 2.x format (this is now required).&lt;br /&gt;
&lt;br /&gt;
 lxc-update-config -c /var/lib/lxc/container-name/config&lt;br /&gt;
&lt;br /&gt;
Make sure you have removed &#039;&#039;&#039;cgroup_enable&#039;&#039;&#039; from your cmdline as this will fail to mount cgroups and fail LXC service.&lt;br /&gt;
&lt;br /&gt;
== Prepare network on host ==&lt;br /&gt;
Set up a [[bridge]] on the host. Example &#039;&#039;/etc/network/interfaces&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
auto br0&lt;br /&gt;
iface br0 inet dhcp&lt;br /&gt;
    bridge-ports eth0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a network configuration template for the guests, &#039;&#039;/etc/lxc/default.conf&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lxc.network.type = veth&lt;br /&gt;
lxc.network.link = br0&lt;br /&gt;
lxc.network.flags = up&lt;br /&gt;
lxc.network.hwaddr = fe:xx:xx:xx:xx:xx&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Grsecurity restrictions ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE&#039;&#039;&#039;: since alpine 3.8 we no longer ship grsecurity and it should not be used in lxc setup.&lt;br /&gt;
&lt;br /&gt;
Some restrictions will be applied when using a grsecurity kernel (Alpine Linux default kernel).&lt;br /&gt;
The most notable is the use of lxc-attach which will not be allowed because of GRKERNSEC_CHROOT_CAPS.&lt;br /&gt;
To solve this we will have to disable this grsec restriction by creating a sysctl profile for lxc.&lt;br /&gt;
Create the following file &#039;&#039;/etc/sysctl.d/10-lxc.conf&#039;&#039; and add:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
kernel.grsecurity.chroot_caps = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are a few other restrictions that can prevent proper container functionality. &lt;br /&gt;
When things do not work as expected always check the kernel log with dmesg to see if grsec prevented things from happening.&lt;br /&gt;
&lt;br /&gt;
Other possible restrictions are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
kernel.grsecurity.chroot_deny_chroot = 0&lt;br /&gt;
kernel.grsecurity.chroot_deny_mount = 0&lt;br /&gt;
kernel.grsecurity.chroot_deny_mknod = 0&lt;br /&gt;
kernel.grsecurity.chroot_deny_chmod = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you finished creating your new sysctl profile you can apply it by restarting sysctl service&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rc-service sysctl restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: Always consult the [https://en.wikibooks.org/wiki/Grsecurity/Appendix/Grsecurity_and_PaX_Configuration_Options Grsecurity documentation] before applying these settings.&lt;br /&gt;
&lt;br /&gt;
== Create a guest ==&lt;br /&gt;
&lt;br /&gt;
=== Alpine Template ===&lt;br /&gt;
&lt;br /&gt;
{{Cmd|lxc-create -n guest1 -f /etc/lxc/lxc.conf -t alpine}}&lt;br /&gt;
&lt;br /&gt;
This will create a &#039;&#039;/var/lib/lxc/guest1&#039;&#039; directory with a &#039;&#039;config&#039;&#039; file and a &#039;&#039;rootfs&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
Note that by default alpine template &#039;&#039;&#039;does not have networking service on&#039;&#039;&#039;, you will need to add it using lxc-console&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If running on x86_64 architecture, it is possible to create a 32bit guest:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|lxc-create -n guest1 -f /etc/lxc/lxc.conf -t alpine -- --arch x86}}&lt;br /&gt;
&lt;br /&gt;
=== Debian template ===&lt;br /&gt;
&lt;br /&gt;
In order to create a debian template container you will need to install some packages:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk add debootstrap rsync}}&lt;br /&gt;
&lt;br /&gt;
Also you will need to turn off some grsecurity chroot options otherwise the debootstrap will fail:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|echo 0 &amp;gt; /proc/sys/kernel/grsecurity/chroot_caps&lt;br /&gt;
echo 0 &amp;gt; /proc/sys/kernel/grsecurity/chroot_deny_chroot&lt;br /&gt;
echo 0 &amp;gt; /proc/sys/kernel/grsecurity/chroot_deny_mount&lt;br /&gt;
echo 0 &amp;gt; /proc/sys/kernel/grsecurity/chroot_deny_mknod&lt;br /&gt;
echo 0 &amp;gt; /proc/sys/kernel/grsecurity/chroot_deny_chmod&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Please remember to turn them back on, or just simply reboot the system.&lt;br /&gt;
&lt;br /&gt;
Now you can run:&lt;br /&gt;
{{Cmd|SUITE{{=}}wheezy lxc-create -n guest1 -f /etc/lxc/lxc.conf -t debian}}&lt;br /&gt;
&lt;br /&gt;
=== Ubuntu template ===&lt;br /&gt;
&lt;br /&gt;
In order to create an ubuntu template container you will need to turn off some grsecurity chroot options:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|echo 0 &amp;gt; /proc/sys/kernel/grsecurity/chroot_caps&lt;br /&gt;
echo 0 &amp;gt; /proc/sys/kernel/grsecurity/chroot_deny_chroot&lt;br /&gt;
echo 0 &amp;gt; /proc/sys/kernel/grsecurity/chroot_deny_mount&lt;br /&gt;
echo 0 &amp;gt; /proc/sys/kernel/grsecurity/chroot_deny_mknod&lt;br /&gt;
echo 0 &amp;gt; /proc/sys/kernel/grsecurity/chroot_deny_chmod&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Please remember to turn them back on, or just simply reboot the system.&lt;br /&gt;
&lt;br /&gt;
Now you can run (replace %MIRROR% with the actual hostname, for example: http://us.archive.ubuntu.com/ubuntu/)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
lxc-create -n guest2 -f /etc/lxc/default.conf -t ubuntu -- -r xenial -a amd64 -u user --password secretpassword --mirror $MIRROR&lt;br /&gt;
&lt;br /&gt;
=== Unprivileged LXC images (Debian / Ubuntu / Centos etc..) ===&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk add gnupg xz&lt;br /&gt;
lxc-create -n container-name -t download}}&lt;br /&gt;
&amp;amp; choose the Distribution | Release | Architecture.&lt;br /&gt;
&lt;br /&gt;
To be able to login to a Debian container you currently need to:&lt;br /&gt;
{{Cmd|rm /lib/systemd/system/container-getty\@.service}}&lt;br /&gt;
&lt;br /&gt;
You can also [http://without-systemd.org/wiki/index.php/How_to_remove_systemd_from_a_Debian_jessie/sid_installationers remove Systemd from the container].&lt;br /&gt;
&lt;br /&gt;
== Starting/Stopping the guest ==&lt;br /&gt;
Create a symlink to the &#039;&#039;/etc/init.d/lxc&#039;&#039; script for your guest.&lt;br /&gt;
{{Cmd|ln -s lxc /etc/init.d/lxc.guest1}}&lt;br /&gt;
&lt;br /&gt;
You can start your guest with:&lt;br /&gt;
{{Cmd|/etc/init.d/lxc.guest1 start}}&lt;br /&gt;
&lt;br /&gt;
Stop it with:&lt;br /&gt;
{{Cmd|/etc/init.d/lxc.guest1 stop}}&lt;br /&gt;
&lt;br /&gt;
Make it autostart on boot up with:&lt;br /&gt;
{{Cmd| rc-update add lxc.guest1}}&lt;br /&gt;
&lt;br /&gt;
You can also add to the container config: &amp;lt;code&amp;gt;lxc.start.auto = 1&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp; {{Cmd|rc-update add lxc}}&lt;br /&gt;
&lt;br /&gt;
to autostart containers by the lxc service only.&lt;br /&gt;
&lt;br /&gt;
== Connecting to the guest ==&lt;br /&gt;
By default sshd is not installed, so you will have to attach to the container or connect to the virtual console. This is done with:&lt;br /&gt;
&lt;br /&gt;
=== Attach to container ===&lt;br /&gt;
&lt;br /&gt;
{{Cmd|lxc-attach -n guest1}}&lt;br /&gt;
&lt;br /&gt;
Just type exit to detach the container again (please do check the grsec notes above)&lt;br /&gt;
&lt;br /&gt;
=== Connect to virtual console ===&lt;br /&gt;
&lt;br /&gt;
{{Cmd|lxc-console -n guest1}}&lt;br /&gt;
&lt;br /&gt;
To disconnect from it, press {{key|Ctrl}}+{{key|a}} {{key|q}}&lt;br /&gt;
&lt;br /&gt;
== Deleting a guest ==&lt;br /&gt;
Make sure the guest is stopped and run:&lt;br /&gt;
{{Cmd|lxc-destroy -n guest1}}&lt;br /&gt;
This will erase everything, without asking any questions. It is equivalent to: {{Cmd|rm -r /var/lib/lxc/guest1}}&lt;br /&gt;
&lt;br /&gt;
== Advanced ==&lt;br /&gt;
&lt;br /&gt;
=== Creating a LXC container without modifying your network interfaces ===&lt;br /&gt;
&lt;br /&gt;
The problem with bridging is that the interface you bridge gets replaced with your new bridge interface.&lt;br /&gt;
That is to say that say you have an interface eth0 that you want to bridge, your eth0 interface gets replaced with the br0 interface that you create. It also means that the interface you use needs to be placed into promiscuous mode to catch all the traffic that could de destined to the other side of the bridge, which again may not be what you want.&lt;br /&gt;
&lt;br /&gt;
The solution is to create a dummy network interface, bridge that, and set up NAT so that traffic out of your bridge interface gets pushed through the interface of your choice.&lt;br /&gt;
&lt;br /&gt;
So, first, lets create that dummy interface (thanks to ncopa for talking me out of macvlan and pointing out the dummy interface kernel module)&lt;br /&gt;
&lt;br /&gt;
{{Cmd|modprobe dummy}}&lt;br /&gt;
&lt;br /&gt;
This will create a dummy interface called dummy0 on your host. To create this interface on every boot, you may need to create a /etc/modprobe.d/dummy.conf with:&lt;br /&gt;
{{Cmd |# Load dummy.ko at boot&lt;br /&gt;
dummy }}&lt;br /&gt;
&lt;br /&gt;
Now we will create a bridge called br0&lt;br /&gt;
&lt;br /&gt;
{{Cmd |brctl addbr br0&lt;br /&gt;
brctl setfd br0 0 }}&lt;br /&gt;
&lt;br /&gt;
and then make that dummy interface one end of the bridge&lt;br /&gt;
&lt;br /&gt;
{{Cmd | brctl addif br0 dummy0 }}&lt;br /&gt;
&lt;br /&gt;
Next, let&#039;s give that bridged interface a reason to exists&lt;br /&gt;
&lt;br /&gt;
{{ Cmd | ifconfig br0 192.168.1.1 netmask 255.255.255.0 up}}&lt;br /&gt;
&lt;br /&gt;
Create a file for your container, let&#039;s say /etc/lxc/bridgenat.conf, with the following settings.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lxc.net.0.type = veth&lt;br /&gt;
lxc.net.0.flags = up&lt;br /&gt;
lxc.net.0.link = br0&lt;br /&gt;
lxc.net.0.name = eth1&lt;br /&gt;
lxc.net.0.ipv4.address = 192.168.1.2/24 192.168.1.255&lt;br /&gt;
lxc.net.0.ipv4.gateway = 192.168.1.1&lt;br /&gt;
lxc.net.0.veth.pair = veth-if-0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and build your container with that file&lt;br /&gt;
&lt;br /&gt;
{{ Cmd | lxc-create -n alpine -f /etc/lxc/bridgenat.conf -t alpine }}&lt;br /&gt;
&lt;br /&gt;
You should now be able to ping your container from your hosts, and your host from your container.&lt;br /&gt;
&lt;br /&gt;
Your container needs to know where to push traffic that isn&#039;t within it&#039;s subnet. To do so, we tell the container to route through the bridge interface br0&lt;br /&gt;
From inside the container run&lt;br /&gt;
&lt;br /&gt;
{{ Cmd | route add default gw 192.168.1.1 }}&lt;br /&gt;
&lt;br /&gt;
The next step is you push the traffic coming from your private subnet over br0 out through your internet facing interface, or any interface you chose&lt;br /&gt;
&lt;br /&gt;
We are messing with your IP tables here, so make sure these settings don&#039;t conflict with anything you may have already set up, obviously.&lt;br /&gt;
&lt;br /&gt;
Say eth0 was your internet facing network interface, and br0 is the name of the bridge you made earlier, we&#039;d do this:&lt;br /&gt;
&lt;br /&gt;
{{ Cmd | echo 1 &amp;gt; /proc/sys/net/ipv4/ip_forward&lt;br /&gt;
iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE&lt;br /&gt;
iptables --append FORWARD --in-interface br0 -j ACCEPT&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Now you should be able to route through your bridge interface to the internet facing interface of your host from your container, just like at home!&lt;br /&gt;
&lt;br /&gt;
You could also have a dhcp server running on your host, and set it up to give IP addresses from your private subnet to any container that requests it, and then have one template for multiple alpine LXC containers, perfect for alpine development :)&lt;br /&gt;
&lt;br /&gt;
=== Using static IP ===&lt;br /&gt;
&lt;br /&gt;
If you&#039;re using static IP, you need to configure this properly on guest&#039;s /etc/network/interfaces. To stay on the above example, modify &#039;&#039;/var/lib/lxc/guest1/rootfs/etc/network/interfaces&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
from&lt;br /&gt;
&lt;br /&gt;
 #auto lo&lt;br /&gt;
     iface lo inet loopback&lt;br /&gt;
 auto eth0&lt;br /&gt;
     iface eth0 inet &#039;&#039;&#039;dhcp&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
to &lt;br /&gt;
&lt;br /&gt;
 #auto lo&lt;br /&gt;
     iface lo inet loopback&lt;br /&gt;
 auto eth0&lt;br /&gt;
     iface eth0 inet &#039;&#039;&#039;static&#039;&#039;&#039;&lt;br /&gt;
     address &amp;lt;lxc-container-ip&amp;gt;   # IP which the lxc container should use&lt;br /&gt;
     gateway &amp;lt;gateway-ip&amp;gt;         # IP of gateway to use, mostly same as on lxc-host&lt;br /&gt;
     netmask &amp;lt;netmask&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== mem and swap ===&lt;br /&gt;
&lt;br /&gt;
{{Cmd|vim /boot/extlinux.conf}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|&lt;br /&gt;
  APPEND initrd{{=}}initramfs-3.10.13-1-grsec root{{=}}UUID{{=}}7cd8789f-5659-40f8-9548-ae8f89c918ab modules{{=}}sd-mod,usb-storage,ext4 quiet cgroup_enable{{=}}memory swapaccount{{=}}1&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== checkconfig ===&lt;br /&gt;
{{Cmd|lxc-checkconfig}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|&lt;br /&gt;
Kernel configuration not found at /proc/config.gz; searching...&lt;br /&gt;
Kernel configuration found at /boot/config-3.10.13-1-grsec&lt;br /&gt;
--- Namespaces ---&lt;br /&gt;
Namespaces: enabled&lt;br /&gt;
Utsname namespace: enabled&lt;br /&gt;
Ipc namespace: enabled&lt;br /&gt;
Pid namespace: enabled&lt;br /&gt;
User namespace: missing&lt;br /&gt;
Network namespace: enabled&lt;br /&gt;
Multiple /dev/pts instances: enabled&lt;br /&gt;
&lt;br /&gt;
--- Control groups ---&lt;br /&gt;
Cgroup: enabled&lt;br /&gt;
Cgroup clone_children flag: enabled&lt;br /&gt;
Cgroup device: enabled&lt;br /&gt;
Cgroup sched: enabled&lt;br /&gt;
Cgroup cpu account: enabled&lt;br /&gt;
Cgroup memory controller: missing&lt;br /&gt;
Cgroup cpuset: enabled&lt;br /&gt;
&lt;br /&gt;
--- Misc ---&lt;br /&gt;
Veth pair device: enabled&lt;br /&gt;
Macvlan: enabled&lt;br /&gt;
Vlan: enabled&lt;br /&gt;
File capabilities: enabled&lt;br /&gt;
&lt;br /&gt;
Note : Before booting a new kernel, you can check its configuration&lt;br /&gt;
usage : CONFIG{{=}}/path/to/config /usr/bin/lxc-checkconfig&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== VirtualBox ===&lt;br /&gt;
&lt;br /&gt;
In order for network to work on containers you need to set &amp;quot;Promiscuous Mode&amp;quot; to &amp;quot;Allow All&amp;quot; in VirtualBox settings for the network adapter.&lt;br /&gt;
&lt;br /&gt;
[[File:VirtualBoxNetworkAdapter.jpg]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Virtualization]]&lt;br /&gt;
&lt;br /&gt;
=== postgreSQL ===&lt;br /&gt;
&lt;br /&gt;
Inside the container run: {{Cmd|chmod go+w /dev/null}} to fix {{Cmd|rc-service postgresql start}}&lt;br /&gt;
&lt;br /&gt;
=== openVPN ===&lt;br /&gt;
&lt;br /&gt;
see [[Setting_up_a_OpenVPN_server#openVPN_and_LXC]]&lt;br /&gt;
&lt;br /&gt;
== LXC 1.0 Additional information ==&lt;br /&gt;
&lt;br /&gt;
Some info regarding new features in LXC 1.0&lt;br /&gt;
 &lt;br /&gt;
https://www.stgraber.org/2013/12/20/lxc-1-0-blog-post-series/&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Howto-lxc-simple]]&lt;/div&gt;</summary>
		<author><name>Mike.edmister</name></author>
	</entry>
</feed>