实用的 Dockerfile 指令 - Some useful commands in Dockerfile.
实用的 Dockerfile 指令。
设置语言
ENV LC_ALL=C.UTF-8 \
LANG=C.UTF-8
设置时区
ENV TZ=Asia/Shanghai
拷贝 ldd
ldd /usr/bin/env | grep "=> /" | awk '{print $3}' | xargs -I '{}' cp -L -n -v '{}' /tmp/libs/
安装 dumb-init
ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.5/dumb-init_1.2.5_x86_64 /usr/local/bin/dumb-init
RUN chmod +x /usr/local/bin/dumb-init
# before the last end line
ENTRYPOINT ["dumb-init", "--"]
删除 test pyc pyo
find /usr/local -depth \
\( \
\( -type d -a \( -name test -o -name tests \) \) \
-o \
\( -type f -a \( -name '*.pyc' -o -name '*.pyo' \) \) \
\) -exec rm -rf '{}'
alpine / debian / ubuntu (通用) 删除无用文件
rm -rf /root/.cache /tmp/* /var/lib/apt/* /var/cache/* /var/log/*
设置 alpine 更新镜像 (Mirror)
ARG MIRROR=mirrors.tuna.tsinghua.edu.cn
ARG SOURCES="/etc/apk/repositories"
RUN sed -i 's/http/https/g' $SOURCES \
&& sed -i 's/dl-cdn.alpinelinux.org/'$MIRROR'/g' $SOURCES
设置 debian 更新镜像 (Mirror)
ARG MIRROR=mirrors.tuna.tsinghua.edu.cn
ARG SOURCES="/etc/apt/sources.list"
RUN sed -i 's/deb.debian.org/'$MIRROR'/g' $SOURCES
设置 ubuntu 更新镜像 (Mirror)
ARG MIRROR=mirrors.tuna.tsinghua.edu.cn
ARG SOURCES="/etc/apt/sources.list"
RUN sed -i 's/archive.ubuntu.com/'$MIRROR'/g' $SOURCES
设置 PyPI 更新镜像 (Mirror)
ENV PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple
一行设置
--no-install-recommends
apt-config dump | grep -we Recommends -e Suggests | sed s/1/0/ | tee /etc/apt/apt.conf.d/999norecommend