Why is the image size of a container larger than a single copy of a docker build when the same file is COPYed multiple times in the same location in a docker file?
For Dockerfile as shown below.
FROM python: 3.9.13
WORKDIR/app
COPY./app
COPY./app
In the current directory, test.txt
has several MB of text files in addition to Dockerfile.
through /test$ls
Dockerfile test.txt
docker build
is performed as follows:
~/test$docker build-t test.
In jhashimoto's answer, "Why is the image size of the container larger than it would have been if I copied it once?" so I will add a little more.
Best Practices for Dockerfile Description
Each command generates one layer at a time.
(omitted)
Once the image is run to generate a container, a writable layer ("container layer") is added over the previous layer. Changes to running containers, such as creating new files, editing existing files, and deleting files, are all written to this write layer.
In other words, whatever the layer below is, all writes made in COPY
will be represented on the new layer.
I don't understand the expectation that the difference will be detected, but it hasn't happened.This is the same with the regular cp
command, which determines whether it can be overwritten, but always overwrites without comparing source and destination content.
I think it is because layers are generated every time the COPY command is issued.
Best Practices for Dockerfile Description|Docker Documents
Each command generates one layer at a time.
caching-Docker have the same file in multiple layers-Stack Overflow
I had a similar QA in my home.
© 2024 OneMinuteCode. All rights reserved.