Current location: home page > Linux O&M > Docker > Getting Started with Alpine Linux

Getting Started with Alpine Linux

Published on: May 6, 2020 Docker 0 comments 8,169 views
This website provides Linux server operation and maintenance, automated script writing and other services. If you need, please contact the blogger on WeChat: xiaozme

Alpine Linux is a Linux distribution based on musl and BusyBox, designed for security, simplicity and resource efficiency. It is very compact and suitable for Docker images. Xiaoz recently learned about Alpine Linux when packaging container images for CCAA/Zdir. Although the sparrow is small, it has all the internal organs, so it is not too convenient.

Docker uses Alpine Linux

Using Commands docker run -it alpine /bin/sh Alpine Linux can be run. Since Alpine Linux has no built-in bash, the sh As a pseudo terminal, when writing shell scripts for Alpine Linux, you should also pay attention to the use of sh instead of bash

Alpine Linux image is very small, less than 6M in size, so it is particularly suitable for container packaging.

Alpine Linux software management

Alpine Linux use apk Command to manage software, similar to CentOS yum Or Debian apt-get , recommended for first use apk update Update the software to avoid failure of normal use. The common commands of apk are as follows:

 #Update software apk update #Search for a software apk search xxx #Install software apk add xxx #Uninstall software apk del xxx #View Help apk -h

Set Alpine Linux time zone

The time zone of Alpine Linux is not the eighth east zone. Some projects need to be synchronized with Beijing time. Therefore, we need to modify the default time zone of Alpine Linux as follows:

 #Install timezone apk add -U tzdata #View time zone list ls /usr/share/zoneinfo #Copy the required time zone file to localtime cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime #View the current time date #To thin the image, you can delete the tzdata apk del tzdata

Modify Alpine Linux software source

If Alpine Linux is used in the domestic network, the domestic image source can be used for better speed. The common domestic image source is as follows:

The configuration file of the software source is located in /etc/apk/repositories , the contents are as follows:

 http://dl-cdn.alpinelinux.org/alpine/v3.11/main http://dl-cdn.alpinelinux.org/alpine/v3.11/community

We can see that the source version of alpine software used here is v3.11 , so we need to keep the version consistent when we modify it, such as changing it to Alibaba's software source:

 http://mirrors.aliyun.com/alpine/v3.11/main http://mirrors.aliyun.com/alpine/v3.11/community

For more software sources, please refer to the official list: https://mirrors.alpinelinux.org/

summary

  • Alpine Linux has no default bash , need to use sh
  • Alpine Linux use apk As Package Manager
  • Recommended software update for first use apk update To avoid some exceptions

Alpine Linux is very compact, but its functions are as good as those of other Linux distributions. It is very suitable for packaging Docker images. When searching for images in the Docker Hub, you will find that many of them are based on Alpine Linux, and they are naturally prepared for containers.

Some contents of this article refer to:


Post reply

Your email address will not be disclosed. Required items have been used * tagging