目前,对于我的 python 项目,我有一个 deploy.sh 文件,它运行一些 apt-get、pip 安装、创建一些目录并复制一些文件....所以这个过程是 git clone 我的私有(private)仓库然后运行 deploy.sh。
现在我在玩 docker,基本的问题是,dockerfile 应该运行 git clone 然后运行 deploy.sh,还是 dockerfile 应该为每个 apt-get、pip 等运行自己的 RUN 而忽略 deploy.sh。 ..这似乎是重复工作(打字)并且有可能不同步?
最佳答案
该工作应该在 dockerfile 中重复。这样做的原因是利用了 docker 的层和缓存系统。举个例子:
# this will only execute the first time you build the image, all future builds will use a cached layer
RUN apt-get update && apt-get install somepackage -y
# this will only run pip if your requirements file changes
ADD requirements.txt /app/requirements.txt
RUN pip install -r requirements.txt
ADD . /app/
另外,你不应该做
git checkout
docker build 中的代码。只需将本地结帐中的文件添加到上例中的图像即可。
关于python - 支持基于 docker 和非基于 docker 的部署,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41421167/