2017-01-02 76 views
0

目前對於我的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 ...這似乎是複製工作(打字),並有可能會不同步?

回答

1

該工作應該在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。只需簡單地將本地簽出的文件添加到上述示例中的圖像即可。

+0

謝謝你的回覆,如果我正在做pip install -e,示例的pip部分是否仍然成立。或python setup.py安裝 – Metalstorm

+0

@Metalstorm不管'pip'行是否由前面的'ADD'行中的文件與緩存中的文件不同而決定。你可以把'-e'放在需求文件中。 – jordanm

+0

這是問題,我沒有requirements.txt文件。所有的要求都依賴於setup.py。但是如果我再加入setup.py,那又是不同的,那麼點應該正確運行? – Metalstorm