项目作者: swoiow

项目描述 :
实用的 Dockerfile 指令 - Some useful commands in Dockerfile.
高级语言:
项目地址: git://github.com/swoiow/dockerfile-cheat-sheet.git
创建时间: 2018-12-20T09:00:20Z
项目社区:https://github.com/swoiow/dockerfile-cheat-sheet

开源协议:GNU General Public License v3.0

关键词:
"docker" "docker-compose" "dockerfile"

下载


dockerfile-cheat-sheet

实用的 Dockerfile 指令。


设置语言

  1. ENV LC_ALL=C.UTF-8 \
  2. LANG=C.UTF-8

设置时区

  1. ENV TZ=Asia/Shanghai

拷贝 ldd

  1. ldd /usr/bin/env | grep "=> /" | awk '{print $3}' | xargs -I '{}' cp -L -n -v '{}' /tmp/libs/

安装 dumb-init

  1. ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.5/dumb-init_1.2.5_x86_64 /usr/local/bin/dumb-init
  2. RUN chmod +x /usr/local/bin/dumb-init
  3. # before the last end line
  4. ENTRYPOINT ["dumb-init", "--"]

删除 test pyc pyo

  1. find /usr/local -depth \
  2. \( \
  3. \( -type d -a \( -name test -o -name tests \) \) \
  4. -o \
  5. \( -type f -a \( -name '*.pyc' -o -name '*.pyo' \) \) \
  6. \) -exec rm -rf '{}'

alpine / debian / ubuntu (通用) 删除无用文件

  1. rm -rf /root/.cache /tmp/* /var/lib/apt/* /var/cache/* /var/log/*

设置 alpine 更新镜像 (Mirror)

  • mirrors.aliyun.com
  • mirrors.ustc.edu.cn
  • mirrors.tuna.tsinghua.edu.cn
  1. ARG MIRROR=mirrors.tuna.tsinghua.edu.cn
  2. ARG SOURCES="/etc/apk/repositories"
  3. RUN sed -i 's/http/https/g' $SOURCES \
  4. && sed -i 's/dl-cdn.alpinelinux.org/'$MIRROR'/g' $SOURCES

设置 debian 更新镜像 (Mirror)

  • mirrors.tuna.tsinghua.edu.cn
  • mirrors.ustc.edu.cn
  • mirrors.163.com
  • mirrors.aliyun.com
  1. ARG MIRROR=mirrors.tuna.tsinghua.edu.cn
  2. ARG SOURCES="/etc/apt/sources.list"
  3. RUN sed -i 's/deb.debian.org/'$MIRROR'/g' $SOURCES

设置 ubuntu 更新镜像 (Mirror)

  1. ARG MIRROR=mirrors.tuna.tsinghua.edu.cn
  2. ARG SOURCES="/etc/apt/sources.list"
  3. RUN sed -i 's/archive.ubuntu.com/'$MIRROR'/g' $SOURCES

设置 PyPI 更新镜像 (Mirror)

  1. ENV PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple

一行设置--no-install-recommends

  1. apt-config dump | grep -we Recommends -e Suggests | sed s/1/0/ | tee /etc/apt/apt.conf.d/999norecommend