Alpine Linux Command Practice
Alpine Linux is the standard for lightweight, security-oriented containers. Because it doesn't use GNU utilities, apt, or systemd, you must learn its specific tools. This track drills muscle memory for the apk package manager (crucial for Dockerfiles) and the OpenRC init system (crucial for Alpine VMs).
Command Reference
apk
| Command | Description |
|---|---|
apk info <package> | Show detailed information about a specific package. |
apk add <package> | Install a new package from the repositories. |
apk del <package> | Remove an installed package and its unneeded dependencies. |
apk search <package> | Search the package repositories for a specific package name. |
apk update | Update the local package index from the repositories. |
apk add --no-cache <package> | Install a package without caching the repository index (best practice for Dockerfiles). |
apk cache clean | Clean the local package cache to free up disk space. |
openrc
| Command | Description |
|---|---|
rc-status | List all services and their current status in the runlevels. |
rc-service <service> start | Start an OpenRC service. |
rc-service <service> stop | Stop a running OpenRC service. |
rc-update del <service> default | Remove a service from the default runlevel so it no longer starts on boot. |
rc-update add <service> default | Add a service to the default runlevel so it starts automatically on boot. |
Key Use Cases
- Install packages in a Dockerfile without bloating the image using apk add --no-cache
- Search the Alpine package repository using apk search
- Start and stop background services using rc-service
- Enable a service to start on boot using rc-update add
- Clean up downloaded package archives to save space using apk cache clean
Frequently Asked Questions
Why use apk add --no-cache in Dockerfiles?
It allows apk to fetch and install packages without storing the repository index locally. This saves disk space and eliminates the need to run 'apk update' and 'rm -rf /var/cache/apk/*' in a single RUN layer.
Does Alpine use systemd?
No, Alpine Linux uses OpenRC as its init system. You use 'rc-service' to manage running services and 'rc-update' to manage boot runlevels instead of 'systemctl'.
What is apk?
apk stands for Alpine Package Keeper. It is the default package manager for Alpine Linux, known for being extremely fast and lightweight.
Ready to master Alpine Linux commands?
Test your muscle memory with our spaced-repetition quiz system. Free forever.
