Dockerfile技巧

zhuxiaoxi發表於2018-07-23

換映象源

Ubuntu

RUN sed -i 's/archive.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list

Alpine

RUN sed -i 's/http:\/\/dl-cdn.alpinelinux.org/https:\/\/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories

移除軟體包快取

Ubuntu

RUN rm -vrf /var/lib/apt/lists/*

Alpine

RUN rm -vrf /var/cache/apk/* && \
    rm -vrf /var/lib/apk/* && \
    rm -vrf /etc/apk/cache/*

常用軟體的安裝使用方式

ping

apt install -yqq inetutils-ping

vnc for firefox

RUN apt update && apt install x11vnc xufb
RUN mkdir /.vnc
RUN x11vnc -storepasswd pass ~/.vnc/passwd
RUN bash -c 'echo "firefox" >> /.bashrc
EXPOSE 5900
CMD ["x11vnc", "-forever", "-usepw", "-create"]

ssh取消pam登陸

RUN sed -ri 's/session required pam_loginuid.so/#session required pam_loginuid.so/g' /etc/pam.d/sshd

debian的非互動式操作

ENV DEBIAN_FRONTEND noninteractive

apache httpd

RUN exec apache2 -D FOREGROUND

以新使用者身份執行

RUN adduser --disabled-login user
RUN su user -c 'command'

相關文章