DSKim
DSKim

Reputation: 595

docker image size getting doubled

I have a question about docker. If I do

docker build -t my_image .
(after a few updates) 
docker build -t my_image .

Then, the size of my_image is not changed, when I check with 'docker images'.

However, if I do

docker build -t my_image .
docker save -o my_image.tar my_image
(after a few updates) 
docker build -t my_image .

then, the size of my image is doubled. It looks like a new image contains both the old and the new one.

Does anybody know why this happens, and how to resolve this issue?

Upvotes: 1

Views: 1766

Answers (1)

O.O.
O.O.

Reputation: 868

The save -o command should output a .tar file in your directory.

If you in your Dockerfile has something like ADD . /app in it, this saved image will also get added, and the image size be doubled because of it.

What you could do is make sure that you do not add the saved my_image.tar when building the image, either by adding some more selection as to what is included in the image, or by saving the .tar somewhere else.

Upvotes: 5

Related Questions