系統 - Docker - 為何Sending build context to Docker daemon會送很大的檔案



參考資訊:
https://stackoverflow.com/questions/26600769/build-context-for-docker-image-very-large

問題如下:

$ sudo docker build -t test .
    Sending build context to Docker daemon  6.812GB
    Step 1/2 : FROM centos:centos6
     ---> 5bf9684f4720
    Step 2/2 : ADD run.sh /tmp/run.sh
     ---> 452184c64be6
    Successfully built 452184c64be6
    Successfully tagged test:latest

解法一:

因為Docker Build會把目前目錄下的所有檔案目錄做傳送的動作,因此,可以移除不必要的檔案,避免傳送過久的問題

解法二:

$ sudo DOCKER_BUILDKIT=1 docker build -t test .
    [+] Building 0.1s (8/8) FINISHED
     => [internal] load .dockerignore                                                                                                                                                        0.0s
     => => transferring context: 2B                                                                                                                                                          0.0s
     => [internal] load build definition from Dockerfile                                                                                                                                     0.0s
     => => transferring dockerfile: 87B                                                                                                                                                      0.0s
     => [internal] load metadata for docker.io/library/centos:centos6                                                                                                                        0.0s
     => [internal] helper image for file operations                                                                                                                                          0.0s
     => [1/2] FROM docker.io/library/centos:centos6                                                                                                                                          0.0s
     => [internal] load build context                                                                                                                                                        0.0s
     => => transferring context: 27B                                                                                                                                                         0.0s
     => CACHED [2/2] ADD run.sh /tmp/run.sh                                                                                                                                                  0.0s
     => exporting to image                                                                                                                                                                   0.0s
     => => exporting layers                                                                                                                                                                  0.0s
     => => writing image sha256:8b6192f579529048c298c483ff8ff766bc6eb841d8f85f1b71d7bc9404a1a49f                                                                                             0.0s
     => => naming to docker.io/library/test


返回上一頁