1. 程式人生 > >build docker映象時傳送到deamo的內容過大問題

build docker映象時傳送到deamo的內容過大問題

當使用Dockerfile Build映象時,發現傳送到Daemo的內容過大

build image:q_build/javaweb:20150910174642
<span style="padding: 0px;"><span style="padding: 0px; color: rgb(255, 0, 0);">Sending build context to Docker daemon 4.768 GB</span></span>
Sending build context to Docker daemon 
Step 0 : FROM 192.168.100.123:5000/q_basic/javaweb:1.0
 ---> 0aab72ab2945
Step 1 : MAINTAINER tyleryan <
[email protected]
> ---> Running in 177026c30954 ---> 3cc2be8f728d Removing intermediate container 177026c30954 Step 2 : ADD monitor.war /usr/local/tomcat/webapps/ ---> b8b56342b691 Removing intermediate container c0108ff358f3 Step 3 : EXPOSE 8080 ---> Running in 451fa4de3e21 ---> 13f7293f7ffe Removing intermediate container 451fa4de3e21 Successfully built 13f7293f7ffe delete locally build docker images:q_build/<span id="0_nwp" style="padding: 0px; width: auto; height: auto; float: none;"><a target=_blank id="0_nwl" href="http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=20&is_app=0&jk=5fc23cd07d5ff9b3&k=javaweb&k0=javaweb&kdi0=0&luki=4&mcpm=0&n=10&p=baidu&q=65035100_cpr&rb=0&rs=1&seller_id=1&sid=b3f95f7dd03cc25f&ssp2=1&stid=9&t=tpclicked3_hc&td=1836545&tu=u1836545&u=http%3A%2F%2Fwww%2Ebubuko%2Ecom%2Finfodetail%2D1089142%2Ehtml&urlid=0" target="_blank" mpid="0" style="padding: 0px; color: rgb(51, 51, 51); text-decoration: none;"><span style="padding: 0px; color: rgb(0, 0, 255); width: auto; height: auto;">javaweb</span></a></span>:20150910174642

但是我們的Dokerfile 非常簡單,那麼這些多出來的內容是從哪裡來的呢。

查閱資料後,

發現Docker Client會預設傳送Dockerfile同級目錄下的所有檔案到Dockerdaemon中。

?

解決辦法有兩種:

1.使用.dockerignore檔案,設定黑名單,該檔案包含的目錄不會被髮送到Docker daemon中

2.將Dockerfile遷移後其他目錄中執行。