Alpine Linux is a lightweight Linux distribution that focuses on security applications. The latest version is Alpine Linux 3.8.0 with a Linux 4.14 kernel.Alpine Linux uses musl libc and busybox to reduce system volume and runtime resource consumption, and it also provides a unique package management tool, apk.
Alpine Linux has been patched with grsecurity/PaX on the kernel, and all programs are compiled as Position Independent Executables (PIE) to enhance the security of the operating system.
Advantages and Problems of Alpine Linux
1. Advantages
The Docker image of Alpine Linux is lightweight (5M in size) and has a complete package management tool (APK).
Docker's official image may replace Ubuntu with Alpine Linux.
2. Questions
Alpine Linux uses musl, which may differ slightly from glibc implementations used by other Linux distributions.
DNS services implemented by musl do not use the search and domain configurations in the resolv.conf file. Note when using DNS for service discovery.
Alpine Linux Package Management-apk Package Management Command
Alpine uses apk for package management and uses the apk --help command to view the complete package management commands. You can refer to the article Installing a bash shell on Alpine Linux first.Common commands are listed below:
1.update: Update local mirror source index from remote mirror source
The update command downloads APKINDEX.tar.gz from each list of mirror sources and stores it in a local cache, typically under /var/cache/apk/(Alpine is in this directory), /var/lib/apk/, /etc/apk/cache/
$ apk update
2.add: Install PACKAGES and automatically resolve dependencies
The add command installs the latest packages from the repository and automatically installs the required dependent packages, or it can add packages from a third-party repository.
$ apk add openssh openntp vim $ apk add --no-cache mysql-client $ apk add docker --update-cache --repository http://mirrors.ustc.edu.cn/alpine/v3.8/main/ --allow-untrusted
Install the specified version of the package:
$ apk add asterisk=1.6.0.21-r0 $ apk add 'asterisk<1.6.1' $ apk add 'asterisk>1.6.1'
3.del: Uninstall and remove PACKAGES
$ apk del openssh openntp vim
4.upgrade: Upgrade currently installed packages
The upgrade command upgrades all packages (typically including the kernel) that are already installed on the system, although you can also specify that only some packages (specified by the -u or -upgrade option) be upgraded.
$ apk update #Update the latest local mirror source $ apk upgrade #Upgrade Software $ apk add --upgrade busybox #Specify to upgrade some packages
5.search: Search packages
The search command searches for available packages, the -v parameter outputs a description, an expense wildcard, and the -d or - Description parameter specifies a query through the package description.
$ apk search #Find all available packages $ apk search -v #Find all available packages and their descriptions $ apk search -v 'acf*' #Find packages by package name $ apk search -v -d 'docker' #Find specific packages by describing files
6.info : List details of PACKAGES or mirror sources
The info command displays information about the package.
$ apk info #List all installed packages $ apk info -a zlib #Display complete package information $ apk info --who-owns /sbin/lbu #Displays the package to which the specified file belongs
Mirror Source Configuration
1. Official Mirror List: http://dl-cdn.alpinelinux.org/alpine/MIRRORS.txt
MIRRORS.txt is the official source of mirrors currently provided by Alpine (the system automatically selects the best source when Alpine is installed)
2. Domestic Mirror Source
Tsinghua TUNA mirror source: https://mirror.tuna.tsinghua.edu.cn/alpine/
China Science and Technology University Mirror Source: http://mirrors.ustc.edu.cn/alpine/
Ali cloud mirror source: http://mirrors.aliyun.com/alpine/
3. How to configure the software source
Take CSK Dayuan for example: just add the corresponding source address in the / etc/apk/repositories file, one address per line.
$ vi /etc/apk/repositories
$ /media/cdrom/apks
http://mirrors.ustc.edu.cn/alpine/v3.5/main
http://mirrors.ustc.edu.cn/alpine/v3.5/community
Alpine Linux init System
Alpine Linux uses an OpenRCinit system like Gentoo.
The following commands can be used to manage init systems
1.rc-update
rc-update is mainly used to add or remove services at different runlevels.
rc-update syntax format:
Usage: rc-update [options] add […]
or: rc-update [options] del […]
or: rc-update [options] [show […]]
Options: [ asuChqVv ]
-a, --all Process all runlevels
-s, --stack Stack a runlevel instead of a service
-u, --update Force an update of the dependency tree
-h, --help Display this help output
-C, --nocolor Disable color output
-V, --version Display software version
-v, --verbose Run verbosely
-q, --quiet Run quietly (repeat to suppress errors)
Example use:
$ rc-update add docker boot #Add a service $ rc-update del docker boot #Delete a service
2.rc-status
rc-status is mainly used for run-level state management.
rc-status syntax format:
Usage: rc-status [options] …
or: rc-status [options] [-a | -c | -l | -r | -s | -u]
Options: [ aclrsuChqVv ]
-a, --all Show services from all run levels
-c, --crashed Show crashed services
-l, --list Show list of run levels
-r, --runlevel Show the name of the current runlevel
-s, --servicelist Show service list
-u, --unused Show services not assigned to any runlevel
-h, --help Display this help output
-C, --nocolor Disable color output
-V, --version Display software version
-v, --verbose Run verbosely
-q, --quiet Run quietly (repeat to suppress errors)
Example use:
$ rc-status #Check the status of the default runlevel $ rc-status -a #Check the status of all runlevels
3.rc-service
rc-service is primarily used to manage the status of services
rc-service syntax format:
Usage: rc-service [options] [-i] …
or: rc-service [options] -e
or: rc-service [options] -l
or: rc-service [options] -r
Options: [ e:ilr:INChqVv ]
-e, --exists tests if the service exists or not
-i, --ifexists if the service exists then run the command
-I, --ifinactive if the service is inactive then run the command
-N, --ifnotstarted if the service is not started then run the command
-l, --list list all available services
-r, --resolve resolve the service name to an init script
-h, --help Display this help output
-C, --nocolor Disable color output
-V, --version Display software version
-v, --verbose Run verbosely
-q, --quiet Run quietly (repeat to suppress errors)
Example use:
$ rc-service sshd start #Start a service. $ rc-service sshd stop #Stop a service. $ rc-service sshd restart #Restart a service.
4.openrc
openrc is primarily used to manage different runlevels.
openrc syntax format:
Usage: openrc [options] []
Options: [ a:no:s:SChqVv ]
-n, --no-stop do not stop any services
-o, --override override the next runlevel to change into when leaving single user or boot runlevels
-s, --service runs the service specified with the rest of the arguments
-S, --sys output the RC system type, if any
-h, --help Display this help output
-C, --nocolor Disable color output
-V, --version Display software version
-v, --verbose Run verbosely
-q, --quiet Run quietly (repeat to suppress errors)
Available runtimes for Alpine Linux
1.default
2.sysinit
3.boot
4.single
5.reboot
6.shutdown
7. Use examples
$ openrc single #Change to single runlevel
8. Other Instructions
$ reboot #Restart the system, similar to shutdown-r now. $ halt #Shut down, similar to shutdown-h now. $ poweroff #Shutdown