It is recommended to use Python: 3.8-Slim-Buster instead of making Python Docker because the current Alpine based Python is slow and possibly unstable

1. The standard PyPI wheel is invalid on Alpine:

Reference cloud.tencent.com/developer/n…

Pythonspeed.com/articles/ba…

Blog.csdn.net/dianfu2892/…

2. Most Linux distributions use the GNU version of the standard C library (Glibc), which is required for Python and almost all C programs. But Alpine Linux uses MUSL, and these binary wheels are compiled for Glibc, so Alpine disables Linux Wheel support.

Most Python packages now include binary wheels on PyPI, which greatly reduces installation time. However, if you’re using Alpine Linux, you’ll need to compile all the C code in every Python package you use.

Alpine Linux causes unexpected runtime bugs While Alpine’s MUSL C library is in theory largely compatible with glibc used by other Linux distributions, in practice the difference can cause problems. When problems do occur, they can be strange and unexpected.

Here are some examples:

The Alpine thread defaults to a smaller stack size, which can cause Python to crash.

One Alpine user found that their Python application was much slower because musl allocates memory differently than Glibc.

I once had trouble looking up DNS in the Alpine mirror running on Minikube (Kubernetes in the VIRTUAL machine) while using WiFi in the WeWork workspace. The reasons are WeWork’s poor DNS setup, the way Kubernetes and Minikube implement DNS, and the way MUSL handles this edge case differently than Glibc. There was nothing wrong with MUSL (it was RFC compliant), but I had to waste time figuring out what the problem was and then switch to glibc-based mirroring.

Another user found problems with time formatting and parsing.

Pit 1: ApK Add download slow, PIP slow

Solution:

# echo "https://mirror.tuna.tsinghua.edu.cn/alpine/v3.4/main" > / etc/apk/repositories \
# && echo "https://mirror.tuna.tsinghua.edu.cn/alpine/v3.4/community" > > / etc/apk/repositories \
#&& echo "https://mirror.tuna.tsinghua.edu.cn/alpine/edge/testing" >> /etc/apk/repositories
# or:
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories

PIP install is slow
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple \
	&& pip config set install.trusted-host mirrors.aliyun.com \
Copy the code

Pit 2: Can’t find bag

Solution: search pkgs.alpinelinux.org/packages, add the specified “Branch” and “Repository” of the source to the/etc/apk/repositories, can apk add

Pit 3: Installation failed

ERROR: mirror.tuna.tsinghua.edu.cn/alpine/v3.4… Bad file descriptor WARNING: Ignoring APKINDEX.79f426e4.tar.gz: Bad file descriptor ERROR: unsatisfiable constraints: Openssh (missing): Required by: world[openSSH]

apk add  openssh --no-cache # add --no-cache to reduce mirror size
Copy the code

Pit 4: The mirror volume is large and you want to delete the package that is no longer used

Apk add Adds the -t parameter

-t, –virtual NAME Instead of adding all the packages to ‘world’, create a new virtual package with the listed dependencies and add that to ‘world’; The actions of the command are easily reverted by deleting the virtual package This means that when you install packages, these packages are not added to the global package. This change can be easily rolled back/deleted. So, if I need GCC to compile a program, but once the program is compiled, I don’t need GCC anymore.

I can install GCC and other required packages in the virtual package, and I can remove all dependencies and remove the virtual package name. Here is an example usage

apk add --virtual mypacks gcc vim
apk del mypacks
Copy the code

All 18 packages installed using the first command will be deleted by the next command.

Note: The same -t parameter overwrites all previous installation packages. It is best not to use -t for dynamically linked libraries, or to ensure that this parameter is not repeated.

Pit 5: Time out of sync

echo "Asia/Shanghai"> / etc/timezone apk add - no - cache tzdata TZ = Asia/Shanghai ln - sf/usr/share/zoneinfo/Asia/Shanghai/etc/localtimeOr simply copy the host area configuration directly
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtim 
Copy the code

Pit 6: the user (group) is incompatible with the host

Solution:

addgroup -g 1200 -S www \
     && adduser -u 1200 -D -S -G www www
Copy the code

Pit 7: incompatible with glibc

Solution:

With the latest stable version of Alpine,

Install the compile environment again
apk add --virtual .build-base --no-cache 
autoconf \
automake \ 
g++ \ 
make \

linux-headers \
bsd-compat-headers 
Copy the code

Pit 8: PIP installation is slow

Solution: Replace the installation source

 pip config set global.index-url https://mirrors.aliyun.com/pypi/simple \
	&& pip config set install.trusted-host mirrors.aliyun.com \
Copy the code

Pothole 9: No extranet access in Docker container or build

Resolve, add running parameters:

–net=host

Pit 10: Docker containers can only access the extranet through proxies

Solution, add environment variables

Add the command line to the Dockerfile before the operation that needs to access the network, or directly run the above two command lines in the container:

exportHttp_proxy = http://16.15.0.1:9011# and:

exportHttps_proxy = http://16.15.0.1:9011Copy the code