6
在容器啓動時,在Dockerfile中使用多個RUN命令來設置映像與單個CMD指令執行腳本的最佳做法是什麼?多個運行指令與單個CMD在Dockerfile中執行安裝腳本初始化容器
例如:
FROM centos:latest
RUN useradd myuser
RUN mkdir -p /usr/local/myapp
ADD ./resources/myapp.zip /usr/local/myapp
RUN unzip /usr/local/myapp/myapp.zip
RUN chown -R myuser:myuser /usr/local/myapp
CMD ["/usr/local/myapp/bin/app"]
與
FROM centos:latest
ADD ./resources/myapp.zip/
ADD ./resources/setup.sh/
RUN chmod +x /setup.sh
# setup.sh will create the user, extract the zip, execute the binary
CMD ["/setup.sh"]
謝謝!我沒有考慮到每次從圖像啓動容器時都會運行setup.sh的事實。就我而言,「app」最好是圖片的一部分,而不是每次都提取。 – Owen
@Owen這就是'CMD'的用途: https://docs.docker.com/engine/reference/builder/#cmd –