The different image size of Docker and AWS ECR

2021-05-07 AWS, Docker

今天回答了一個關於 Container image 問題,覺得蠻有趣的小知識順手紀錄一下

起因是發問者在本機 Docker 建立了一個 Windows Container 接近 9GB 左右的大小 (Windows 在這個時代簡直是巨獸 …):

$ docker inspect ${imageId}

"Size": 8816782031

但是當這個 Windows Container 推送到 AWS ECR 時再查詢 image size 竟然只剩下 1.2GB 左右:

$ aws ecr describe-images --repository-name windows

"imageSizeInBytes": 1231825601,

查了一下 AWS ECR Document 有講到這是 Docker client 的行為:

Starting with Docker version 1.9, the Docker client compresses image layers before pushing them to a V2 Docker registry. The output of the docker images command shows the uncompressed image size. Therefore, keep in mind that Docker might return a larger image than the image shown in the AWS Management Console.

在本機執行 docker image 時是原始 image size,而 Docker 1.9 版本之後 docker push image 到 registry 之前會將 image 進行壓縮,所以 AWS ECR 或 Docker Hub 等 registry 存放的 image 都是被壓縮過的。

給 Mr. 沙先生一點建議

彙整

分類

展開全部 | 收合全部

License

訂閱 Mr. 沙先生 的文章

輸入你的 email 用於訂閱