python - 支持基于 docker 和非基于 docker 的部署

标签 python ubuntu docker deployment

目前,对于我的 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/

相关文章:

python - 使用 TensorFlow `` grad_loss/grad_ys`` 参数添加梯度

python - Selenium 的应用程序没有响应 - 不显示进度条,并且在任务完成之前不在控制台中发出文本

ruby-on-rails - 为什么我的 Cron 作业不能正常工作?

windows - Docker 组合容器失败并退出,代码 127 丢失/bin/env bash

java - 如何在 gitlab-ci docker 构建过程中拉取共享库?

nginx - Docker 登录仅适用于守护进程,但不适用于 Docker 事件服务

python - Python OpenCV滑动窗口对象检测

node.js - Ubuntu:端口 80 上的 Http-server 正在启动,但无法从浏览器访问?

ubuntu - 如何修改 Elasticsearch 堆大小? - 未使用 jvm.options

python - Django 在哪里存储其测试数据库