Change pip Registry in Dockerfile
Default pip resigtry is desperately slow in China. That makes building python docker image a PITA. Luckily we can config Dockerfile with a different pip registry:
# Dockerfile# Set environment variablesENV PYTHONDONTWRITEBYTECODE 1ENV PYTHONUNBUFFERED 1...# Upgrade pip then change pip registryRUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -URUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple...RUN pip install --no-cache-dir -r requirements.txt
--no-cache-dir
will shrink the image size by disabling the cache. It's a good practice to use it for building docker images.
If changing ubuntu source is needed:
# DockerfileRUN sed -i s/archive.ubuntu.com/mirrors.aliyun.com/g /etc/apt/sources.list&& sed -i s/security.ubuntu.com/mirrors.aliyun.com/g /etc/apt/sources.list&& apt-get update && apt-get upgrade