Home · Help · Setting up an Alpine Linux server
Setting up an Alpine Linux server: apk, OpenRC and musl
Alpine is the smallest system in our range. Instead of glibc and GNU tools it uses musl and BusyBox, instead of systemd OpenRC. This guide applies to Alpine 3.24 on an Alpine server.
What is installed
- OpenRC as the init system.
syslog,crondand the network run at boot. - apk with the package sources
mainandcommunity. - BusyBox with the shell
ash. bash is not installed. - doas instead of sudo. OpenSSH for logging in is added when the server is set up.
1. Updating and installing packages
apk update && apk upgrade
apk add nginx
apk search php
apk del removes a package again. The explicitly installed packages are listed in /etc/apk/world.
2. Managing services
Unlike Debian, an installed service does not start by itself. Start it once and add it to the boot process:
rc-service nginx start
rc-update add nginx default
| Purpose | Alpine | Debian with systemd |
|---|---|---|
| Start, stop, restart | rc-service nginx start|stop|restart | systemctl start|stop|restart nginx |
| Status | rc-service nginx status | systemctl status nginx |
| Enable at boot | rc-update add nginx default | systemctl enable nginx |
| Disable at boot | rc-update del nginx default | systemctl disable nginx |
| All services | rc-status | systemctl list-units |
3. Setting up your own service
A few lines are enough for a program without its own init script. Save it as /etc/init.d/meindienst and adjust the program and user:
#!/sbin/openrc-run
name="meindienst"
command="/usr/local/bin/meindienst"
command_user="dienst"
command_background=true
pidfile="/run/${RC_SVCNAME}.pid"
depend() {
need net
}
chmod 755 /etc/init.d/meindienst
rc-update add meindienst default
rc-service meindienst start
4. cron and logs
crond is already running. Your own jobs go into /etc/crontabs/root with crontab -e. Scripts in /etc/periodic/daily and the neighbouring folders run daily, hourly, weekly or monthly. BusyBox writes the system logs to /var/log/messages.
5. Privileges with doas
For a user who may run commands as root:
adduser betrieb
adduser betrieb wheel
echo 'permit persist :wheel' > /etc/doas.d/wheel.conf
After that, this user runs commands with doas, for example doas apk upgrade. If you prefer sudo, install it with apk add sudo.
musl instead of glibc
Programs from apk packages and from source code run without restrictions. Prebuilt binaries built for glibc often do not start. The package gcompat helps in simple cases. If there is a separate build for musl or Alpine, it is the better choice. For software that is only released for glibc, a server with Debian or Ubuntu is the right fit.
Upgrading to the next release
A new Alpine release appears every six months. Before upgrading, create a snapshot in the customer portal, then replace the version number in /etc/apk/repositories with the new one, here using 3.25 as an example, and update:
sed -i 's/v3.24/v3.25/g' /etc/apk/repositories
apk update && apk upgrade --available
reboot
Container and kernel
Alpine runs as a container with Incus. It uses the kernel of the host. Kernel packages and your own kernel modules are therefore not applicable. If you need your own kernel, choose a vServer with KVM.
Frequently asked questions
- How much memory does Alpine need?
- The system itself needs only a few megabytes. The services running on it determine the requirement.
- Why are commands I know from Debian missing?
- BusyBox includes slim versions of the usual tools. The full GNU versions are available as packages, for example
coreutils,findutils,grepandbash.
See also: First steps on your vServer Setting up a Devuan server without systemd