配置阿里 apk源:
/etc/apk/repositories:
https://mirrors.aliyun.com/alpine/v3.13/main alpine-v3.13-community安装包下载_开源镜像站-阿里云
或者使用命令
sed -i 's@dl-cdn.alpinelinux.org@mirrors.aliyun.com@g' /etc/apk/repositories
dockerfile制作时
apk安装时需要添加 --no-cache,比如 apk add --no-cache tzdata
设置时区:
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \&& echo "Asia/Shanghai" > /etc/timezone
# 清理运行时不需要的软件和安装缓存
apk del tzdata &&rm -rf /var/cache/apk/* && rm -rf /root/.cache && rm -rf /tmp/*
参考样例:
FROM python:3.5-alpine3.8
LABEL author example@mail.com
RUN echo "http://mirrors.aliyun.com/alpine/v3.8/main" > /etc/apk/repositories \&& apk add --no-cache tzdata \&& cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \&& echo "Asia/Shanghai" > /etc/timezone \&& pip3 install \--index-url http://mirrors.aliyun.com/pypi/simple \--trusted-host mirrors.aliyun.com \--no-cache-dir \flask==1.0.2 \&& apk del tzdata \&& rm -rf /var/cache/apk/* \&& rm -rf /root/.cache \&& rm -rf /tmp/*
WORKDIR /CMD ["/bin/sh"]