Install Alpine on LXD
LXD is an easy to use daemon and client for managing LXC containers. It is included by default in Ubuntu 16.04 and later versions. It may become available in other distributions, such as debian. If you are not familiar at all with LXC or LXD, start directly with LXD. For detailed instructions on how to use it, lookup Stéphane Graber's blog post series on LXD.
With LXD you can start an Alpine Linux container in seconds, in practically any Ubuntu 16.04 (or later) system, including:
- A standalone system
- An Amazon EC2 instance
- An OpenStack KVM VPS
These instructions assume you are running on an amd64 (x86_64) platform.
Before you launch LXD containers, you must configure LXD:
Accept all the defaults. You can rerun this if you have no containers. The ZFS storage method is recommended, because of its ability to create instant snapshots and copies of containers, but it requires additional configuration and it is not available everywhere (e.g. in a VPS host). dir will do just fine for a demo.
To change the networking configuration:
To install Alpine Linux edge version run:
To install Alpine Linux 3.5 run:
To enter a shell in the container:
Fixing the container
Once you create the container, edit /etc/inittab and comment out all lines that start with "tty". Otherwise, the container will keep writing warnings on /var/log/messages. Here's a script to automate this:
#!/bin/sh sed -i 's/^tty/# tty/g' /etc/inittab # clean messages rm /var/log/messages
Let's say this script is called fixgetty.sh. To copy it to the container, use the following:
After you fix /etc/inittab, reboot the container:
The container has outgoing access to the network, but no incoming public access, since it doesn't have a public ip. You can provide incoming access using several networking techniques:
- On a LAN, it suffices to add a route through the host LXD node
- Use an iptables configurator, such as shorewall
- For HTTP/HTTPS access, use an HTTP reverse proxy/load balancer, such as pound, to redirect HTTP requests to various containers. You can run the HTTP reverse proxy in an Alpine container, once you redirect the ports that you want to it, (using iptables).