docker alpine is a kind of image. The Alpine Docker image inherits the advantages of the Alpine Linux distribution. Compared with other Docker images, its capacity is very small, only about 5MB, and it has very friendly package management. mechanism.
The operating environment of this article: ubuntu 18.04 system, Docker version 20.10.11, Dell G3 computer.
What is docker alpine?
Alpine operating system is a security-oriented lightweight Linux distribution. It is different from ordinary Linux distributions. Alpine uses musl libc and busybox to reduce the system size and runtime resource consumption. However, its functions are much more complete than busybox, so it is increasingly favored by the open source community. While maintaining weight, Alpine also provides its own package management tool apk. You can query package information through the https://pkgs.alpinelinux.org/packages website, or you can directly query and install various software through the apk command.
Alpine is a Linux distribution maintained by a non-commercial organization and supports a wide range of scenarios. It is specially optimized for experienced/heavy Linux users, focusing on security, performance and resource efficiency. Alpine images can be applied to more common scenarios and are an excellent basic system/environment suitable for production.
The Alpine Docker image also inherits these advantages of the Alpine Linux distribution. Compared with other Docker images, its capacity is very small, only about 5 MB (compared to nearly 200 MB for Ubuntu series images), and it has a very friendly package management mechanism. The official image is from the docker-alpine project.
Currently, Docker officials have begun to recommend using Alpine to replace the previous Ubuntu as the basic mirror environment. This brings several benefits. Including accelerated image download speed, improved image security, more convenient switching between hosts, and occupying less disk space.
The following table is a size comparison of official images:
REPOSITORY TAG IMAGE ID VIRTUAL SIZE alpine latest 4e38e38c8ce0 4.799 MB debian latest 4d6ce913b130 84.98 MB ubuntu latest b39b81afc8ca 188.3 MB centos latest 8efe422e6104 210 MB
Get and use the official image
Since the image is very small, The download time is often very short. Readers can directly use the docker run command to directly run an Alpine container and specify the Linux command to run, for example:
$ docker run alpine echo '123' 123
Migrate to Alpine base image
Currently, most Docker official images already support Alpine as a base image and can be easily migrated.
For example:
ubuntu/debian -> alpine python:3 -> python:3-alpine ruby:2.6 -> ruby:2.6-alpine
In addition, if you use the Alpine image to replace the Ubuntu base image, you need to use the apk package manager to replace the apt tool when installing the software package, such as
$ apk add --no-cache <package>
Alpine The name of the software installation package may be different from other distributions. You can search and determine the installation package name on the https://pkgs.alpinelinux.org/packages website. If the required installation package is not in the main index, but is in the test or community index. Then you can use these installation packages as follows.
$ echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories $ apk --update add --no-cache <package>
Since accessing the apk warehouse in China is slow, it is recommended to replace the warehouse address with the domestic mirror before using the apk.
RUN sed -i "s/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g" /etc/apk/repositories \ && apk add --no-cache <package>
Recommended learning: "Docker Video Tutorial"
The above is the detailed content of what is docker alpine. For more information, please follow other related articles on the PHP Chinese website!