For the complete documentation index, see llms.txt. This page is also available as Markdown.

33.5 Alpine Jail

Create the Alpine Jail Base System

Build the base system:

# Download the Alpine Linux 3.17.1 minirootfs image
# fetch https://mirrors.ustc.edu.cn/alpine/v3.17/releases/x86_64/alpine-minirootfs-3.17.1-x86_64.tar.gz

# Create the Alpine Jail root directory
# mkdir -p /usr/jails/alpine

# Extract the minirootfs to the Jail root directory
# tar zxf alpine-minirootfs-3.17.1-x86_64.tar.gz -C /usr/jails/alpine/

# Create necessary device nodes
# touch /usr/jails/alpine/dev/shm
# touch /usr/jails/alpine/dev/fd

Manage Mount Files

Create the /etc/fstab.alpine file. The /tmp mount is commented out to avoid exposing the entire host /tmp directory to the Jail, improving security:

devfs      /usr/jails/alpine/dev      devfs       rw                      0  0
tmpfs      /usr/jails/alpine/dev/shm  tmpfs       rw,size=1g,mode=1777    0  0
fdescfs    /usr/jails/alpine/dev/fd   fdescfs     rw,linrdlnk             0  0
linprocfs  /usr/jails/alpine/proc     linprocfs   rw                      0  0
linsysfs   /usr/jails/alpine/sys      linsysfs    rw                      0  0
#/tmp       /usr/jails/alpine/tmp      nullfs      rw                      0  0  # Commented out to avoid exposing the entire host /tmp directory to the Jail

Manage the Jail Template

Add the following to the /etc/jail.conf file:

Set up boot-time startup, then start immediately:

Firewall Network Access

Allow network access in the pf firewall, using the same method as described earlier:

Configure OpenRC for the Base System

Enter the Jail. The minirootfs only provides a basic environment; installing OpenRC gives full service management capabilities:

Modify the Alpine configuration in the /etc/jail.conf file:

Restart the alpine Jail:

Last updated