Manajemen Paket
Dasar apk
apk update # refresh package index apk upgrade # upgrade all packages apk add curl git vim # install packages apk del curl # remove a package apk search nginx # search for packages
Info Paket
apk info # list installed packages apk info -a nginx # detailed package info apk info -L nginx # list files in package apk policy nginx # show available versions
Virtual Package
# Install build deps as a group, remove later apk add --virtual .build-deps gcc musl-dev make && make install apk del .build-deps
Repository
# /etc/apk/repositories https://dl-cdn.alpinelinux.org/alpine/v3.20/main https://dl-cdn.alpinelinux.org/alpine/v3.20/community @edge https://dl-cdn.alpinelinux.org/alpine/edge/testing
Layanan
Manajemen Layanan OpenRC
rc-service nginx start # start service rc-service nginx stop # stop service rc-service nginx restart # restart service rc-service nginx status # check status
Manajemen Runlevel
rc-update add nginx default # enable at boot rc-update del nginx default # disable at boot rc-update show # list all services rc-status # show running services
Runlevel
sysinitInisialisasi sistem (filesystem, jam)
bootLayanan sistem dasar (jaringan, syslog)
defaultLayanan normal (web server, daemon)
shutdownTugas saat shutdown
Konfigurasi
File Konfigurasi Utama
/etc/apk/repositoriesURL repository paket
/etc/hostnameHostname sistem
/etc/network/interfacesKonfigurasi interface jaringan
/etc/conf.d/Konfigurasi per-layanan
/etc/motdPesan saat login
Setup Sistem
setup-alpine # interactive full setup setup-timezone # set timezone setup-keymap # configure keyboard layout setup-hostname myhost # set hostname
Timezone
apk add tzdata cp /usr/share/zoneinfo/US/Eastern /etc/localtime echo "US/Eastern" > /etc/timezone apk del tzdata # optional: remove to save space
Jaringan
Konfigurasi Interface
# /etc/network/interfaces auto eth0 iface eth0 inet dhcp # --- static --- iface eth0 inet static address 192.168.1.10/24 gateway 192.168.1.1
Perintah Jaringan
ip addr show # show IP addresses ip route show # show routing table ip link set eth0 up # bring interface up setup-interfaces # interactive net config
DNS & Firewall
# DNS: /etc/resolv.conf nameserver 1.1.1.1 nameserver 8.8.8.8 # Firewall apk add iptables iptables -L -n # list rules
Pengguna
Manajemen User
adduser alice # create user (interactive) adduser -D -s /bin/sh bob # non-interactive, set shell deluser alice # delete user passwd alice # set/change password
Group & Sudo
addgroup devs # create group addgroup alice devs # add user to group apk add doas # lightweight sudo alternative # /etc/doas.conf permit persist alice as root
System User
adduser -S -D -H -s /sbin/nologin myapp # -S system user -D no password # -H no home dir -s no shell
Disk & Storage
Perintah Filesystem
df -h # disk usage summary du -sh /var/log # directory size lsblk # list block devices mount /dev/sda1 /mnt # mount device umount /mnt # unmount
LBU (Alpine Local Backup)
# For diskless/data modes — persist changes across reboots lbu status # show uncommitted changes lbu commit # save changes to boot media lbu list # list backed-up files lbu include /etc/myconf # add path to backup
Setup Disk
setup-disk # interactive disk install setup-disk /dev/sda # install to specific disk # Modes: sys (traditional), data, diskless
Docker Base Image
Kenapa Alpine untuk Docker
~5 MB base imagevs ~80 MB untuk Debian slim
musl libcLebih kecil dari glibc (ada isu kompatibilitas)
apk package managerCepat, tanpa cache secara default
Attack surface minimalPaket lebih sedikit = CVE lebih sedikit
Dockerfile Minimal
FROM alpine:3.20 RUN apk add --no-cache python3 py3-pip COPY app.py /app/ CMD ["python3", "/app/app.py"]
Multi-Stage Build
FROM golang:1.22-alpine AS builder WORKDIR /src COPY . . RUN go build -o /app FROM alpine:3.20 COPY --from=builder /app /app CMD ["/app"]
Gotcha Umum
--no-cacheSelalu gunakan agar image tetap kecil
musl vs glibcBeberapa binary butuh paket gcompat
Bash tidak ada secara defaultGunakan /bin/sh atau apk add bash
Timezone tidak tersediaInstall tzdata jika diperlukan
Pola Umum
Install Build Tools
apk add --no-cache build-base # gcc, make, etc. apk add --no-cache python3-dev # Python headers apk add --no-cache linux-headers # kernel headers
Cron Job
# Add a cron job echo "*/5 * * * * /usr/local/bin/task.sh" \ | crontab - rc-service crond start rc-update add crond default
Aktifkan SSH
apk add openssh rc-service sshd start rc-update add sshd default # Config: /etc/ssh/sshd_config
Upgrade Versi Alpine
# Edit /etc/apk/repositories: change v3.19 → v3.20 apk update apk upgrade --available sync && reboot