I would like to reduce the docker image.
test/i386-ubuntu 1.1.486ce872ce9593 daysago 8.682 GB
test/i386-ubuntu 1.1.37f25a5c2b7ee 3daysago 7.284GB
test/i386-ubuntu 1.1.2 a8177a2a57ea 3 days ago 2.012 GB
test/i386-ubuntu 1.1.158ff7a098c5f 3daysago381.7 MB
The above four images are hierarchical.I would like to delete unnecessary files from this 1.1.4 and reduce them to a new image.
I also saw an article saying that the meta file is deleted by docker export.I don't really understand what this meta-file means, but I want to avoid unintended disappearance.
How can I put together my image and create an image of a diet image?
If you know, please let me know if you are referring to a file like a meta file.
The best way to create a small Docker image is to rebuild a small base image, such as Alpine Linux or BusyBox, with minimal changes.
But this is probably not something I want to do, so I'll give you another way.
The reason for the large size of the Docker image is the increase in the number of layers.
test/i386-ubuntu:1.1.4
is larger because it is layered from 1.1.1
.
Whatever you do on top of this image will not reduce the size.
I think the only way to reduce the size is to create a new image of layers in one layer.
Docker doesn't have the ability to put layers together yet.
Suggested in PR#13929 or PR#4232 but it seems to have been rejected.
PR#22641 is the docker build
plus the option --squash
and has already been merged and
I think I can use it to organize the layers, but it hasn't been released yet.
Third-party docker-flatten or docker-squash
There is , but it is your responsibility to use it.
Other methods include using docker export
and docker import
.
docker export<container ID>|docker import-<image name>:<tag>
However, if you do this, the attributes given to the image in dockerbuild
(Dockerfile) will disappear.
Examples include VOLUME
, EXPOSE
, and ENV
.I think it's good to think that only the file system is retained.
Note that docker export
targets containers, not images.
Similar commands for images include docker save
/docker load
, which cannot be used to reduce the image size because it keeps layers together.
docker export
You can create a smaller image by deleting unnecessary files and packages in the container or by deleting the cache with apt-get clean
.
© 2025 OneMinuteCode. All rights reserved.