目前对于我的python项目,我有一个deploy.sh文件,它运行一些apt-get的,pip安装,创建一些dirs并复制一些文件….所以这个过程是git clone我的私人回购然后运行deploy.sh。支持基于docker和non docker的部署
现在我在玩docker,基本问题是,如果dockerfile运行git clone然后运行deploy.sh,或者dockerfile应该为每个apt-get,pip等自己运行并忽略deploy.sh …这似乎是复制工作(打字),并有可能会不同步?
===========解决方案如下:
该工作应该在dockerfile中复制。这是为了充分利用码头层和缓存系统。以这个例子:
# 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/
另外,你不应该在docker build中执行你的代码的git checkout
。只需简单地将本地签出的文件添加到上述示例中的图像即可。