Alpine Linux is a lightweight, security-oriented Linux distribution based on musl libc and BusyBox. Some key things to know about Alpine Linux:
- It’s designed to have a very small footprint, with the base image being only around 5MB in size. This makes it popular for use in containers and embedded systems.
- It uses musl libc instead of glibc as its C library implementation. Musl is lighter weight than glibc.
- The default package manager is apk, which allows installing, updating and removing packages in the .apk format.
- It uses OpenRC as the init system instead of systemd, which helps reduce overhead.
- Being security-focused, it applies proactive security patching and enables security hardening features by default.
- Popular uses include running it as a lightweight container base image for Docker and Kubernetes, on embedded devices like routers, and on servers where minimal footprint is desired.
- The official repositories contain over 13,000 packages, but the available packages are more limited than larger distros due to Alpine’s minimalism.
So in summary, Alpine emphasizes security and extreme compactness, making it well-suited for containerized environments and constrained hardware while still being a capable general-purpose Linux distribution.
Compared with Debian, both package manager and init system are different.
Here is a table to compare the apk
package manager in Alpine Linux with the apt-get
package manager used in Debian-based distributions like Ubuntu:
Feature | apk (Alpine Linux) | apt-get (Debian, Ubuntu) |
---|---|---|
Command Syntax | apk add package | apt-get install package |
Update Repositories | apk update | apt-get update |
Upgrade Packages | apk upgrade | apt-get upgrade |
Remove Package | apk del package | apt-get remove package |
Search Packages | apk search pattern | apt-cache search pattern |
List Installed | apk list --installed | dpkg --list |
Package Information | apk info package | apt-cache show package |
Clean Cache | apk cache clean | apt-get clean |
C Library | musl libc | glibc |
Default Install Size | ~5MB | ~200MB+ |
Package Format | .apk | .deb |
No. of Packages | ~13,000 | ~51,000+ (Ubuntu) |
Repositories | /etc/apk/repositories | /etc/apt/sources.list |
Init System | OpenRC | systemd (Ubuntu) |
As the apk repositories is much smaller than the apt-get, so it is very important to choose the repositories address.
Go to https://pkgs.alpinelinux.org/ and search the package you want, get the branch name.
Go to https://mirrors.alpinelinux.org/ to choose a fast mirror and configure it.
nano /etc/apk/repositories
http://ftp.udx.icscoe.jp/Linux/alpine/edge/main
http://ftp.udx.icscoe.jp/Linux/alpine/edge/community
http://ftp.udx.icscoe.jp/Linux/alpine/edge/testing
# for PHP7
http://ftp.udx.icscoe.jp/Linux/alpine/v3.14/community/
http://ftp.udx.icscoe.jp/Linux/alpine/v3.14/main/
http://ftp.udx.icscoe.jp/Linux/alpine/v3.14/releases/
Here’s a table comparing the OpenRC init system used in Alpine Linux and the systemd init system used in many other Linux distributions:
Feature | OpenRC | systemd |
---|---|---|
Init System Type | Dependency-based | Parallelized |
Service Management | rc-service command | systemctl command |
Service Definition | Scripts in /etc/init.d | Unit files in /etc/systemd/system |
Dependency Handling | Dependency tree | Declarative dependencies |
Process Supervision | Traditional Unix processes | Cgroups for process tracking |
Boot Process | Sequential startup | Parallel startup |
System Logging | Traditional syslog | Journal for system logs |
Additional Components | – | systemd-logind, systemd-networkd, etc. |
Resource Usage | Lightweight | More resource-intensive |
Compatibility Layer | – | systemd-sysv for SysV init scripts |
Service Monitoring | cronie, syslog-ng | systemd-journald, systemd-timesyncd |
Adopted By | Gentoo, Alpine Linux | RedHat, Debian, Arch Linux, Ubuntu |
Start Service | rc-service <service> start | systemctl start <service> |
Stop Service | rc-service <service> stop | systemctl stop <service> |
Restart Service | rc-service <service> restart | systemctl restart <service> |
Check Service Status | rc-service <service> status | systemctl status <service> |
The status
command is used to check the current running status of a service.
Here is the script to install the LNMP on alpine linux.
apk update
apk upgrade
apk add nginx
apk add mysql mysql-client
#apk add mariadb mariadb-client (the same)
apk add php7-fpm php7-mcrypt php7-soap php7-openssl php7-gmp php7-pdo_odbc php7-json php7-dom php7-pdo php7-zip php7-mysqli php7-sqlite3 php7-apcu php7-pdo_pgsql php7-bcmath php7-gd php7-odbc php7-pdo_mysql php7-pdo_sqlite php7-gettext php7-xmlreader php7-xmlrpc php7-bz2 php7-iconv php7-pdo_dblib php7-curl php7-ctype
rc-service nginx start
rc-service php-fpm7 start
rc-service mariadb start