Install Alpine on LXC

From Alpine Linux

LXC

LXC is an operating-system-level virtualization method for running multiple isolated Linux systems (containers) on a control host using a single Linux kernel.

With LXC you can run Alpine Linux on container and start services in it using native Alpine Linux' init system (openrc).

This is instruction on how to install Alpine Linux on LXC container.

Preparation

LXC installation

You have to install "lxc" package on your host system. For example, in Arch Linux you can install it by running:

# pacman -S lxc

Bridge creation

You also have to create network bridge on your host.

Setting up bridge in Arch Linux or Arch Linux based systems

Setting up bridge in Ubuntu or Ubuntu based systems

Here is example, how to setup bridge with netctl:

Copy sample file "bridge"

# cp /etc/netctl/examples/bridge /etc/netctl/myBridge

Modify your bridge configuration file as needed (network interfaces: eno1 and tap0 are, of cource, according to your needs)

Contents of /etc/netctl/myBridge

Description="Bridge connection" Interface=br0 Connection=bridge BindsToInterfaces=(eno1 tap0) IP=dhcp

Stop active connection

# systemctl stop dhcpcd

Start your bridge

# netctl start myBridge

Perhaps you may wish to setup your system to start your bridge automatically at boot time.

Container creation

To install Alpine Linux edge version run:

# lxc-create --name alpine-edge -t alpine -- --release edge

You can also configure shared directory which will be accessible from both host and container. In this example we make host's /media/d directory available in container

# mkdir /var/lib/lxc/alpine-edge/rootfs/media/d

Add the following lines to the container's configuration file:

Contents of /var/lib/lxc/alpine-edge/config

... lxc.network.type = veth lxc.network.flags = up lxc.network.link = br0 lxc.mount.entry=/media/d media/d none bind 0 0

Booting container:

# lxc-start -n alpine-edge

Shutting down container:

# lxc-stop -n alpine-edge

Going to Alpine Linux console:

# lxc-attach -n alpine-edge

Container setup

Modify your apk/repositories configuration file. It is recommended to include "main", "testing" and "community" repositories.

Contents of /etc/apk/repositories

http://dl-cdn.alpinelinux.org/alpine/edge/main http://dl-cdn.alpinelinux.org/alpine/edge/testing http://dl-cdn.alpinelinux.org/alpine/edge/community

Upgrading your Alpine Linux system:

# apk update && apk upgrade -a

Starting services:

# /etc/init.d/service_name start

or

# rc-service service_name start

Adding services to autostart

# rc-update add service_name

Restarting your container:

reboot