Image increases size itself

Hello everyone!

I have a linux VM with fedora server distro. In it I have several containers running without any problem. But I have a specific one with an image that increases its size with every new version of that buildt.

In my case I use a system that uploads the code of my api to the fedora server. The code has the dockerfile to build the image, it is a Flask API that uses libraries to work with images and IA predictions. For each upload the system creates a new image with a the same name different tag which references the new version. Then, the previous image (with the same name but different tag) is removed and it runs a new docker with the latest image version.

The problem comes when the image is built. On my Windows 11 computer, where I develop the API, build the images, and run the dockers, the image size is 13GB. But when I deploy the image on the server its size is 30GB, here is the first case I don’t understand. Not only the size increases compared to the windows system, the size of the image created in the server is bigger than the previous version, it increases the size arround 2/3 GB more.

This is my Dockerfile

Anyone can help me to understand and recommend me any tip or something to solve these cases?

If anyone has any media content or data write me!

Thanks to all!

As long as you don’t use docker build -t python:3.8.19 . to build the image, it should not use the previous build image to create the new one.

The most likely thing is that the COPY . . instruction copies more files into the image with every execution, especially if the folder contains data that is not supposed to be in the image. For instance you don’t want your .git folder to be included in your image, so you would put it into the .dockerignore file + every other folder or file you want to exclude when copying data from the build context into the image.

Some clever people store large models in git, and update the models frequently, so that the history of models end up in the git metadata and be part of the image. Please share the output of git count-objects -vH

Thks for your help, I wasn’t using the .dockerignore. With the .dockerignore the size is too much lower, that was the key!