Docker Community Forums

Share and learn in the Docker community.

Docker image size is becoming huge after DOCKER COMMIT

I’m started using a docker with basic docker image Linux - x86-64 ( latest ). I have pulled this image with the command

docker pull ubuntu

I run this docker using the command

docker run -it ea4c82dcd15a /bin/bash

where “ea4c82dcd15a” is the IMAGE ID for the image.
This allows me to run the image successfully and work with it. But after doing some work in the container and storing some of my small work data into the container, committing the docker makes the docker image size too huge as it sometimes crosses the size in GBs.
I use below command to commit the docker

docker commit -p -a <author> -m <message> <container_id> <label>:<tag>

But as I told you this is creating a docker image including my work data but with a large size of the image.
Can anyone please clear if I’m doing anything wrong in the whole process or there is any other reason for this is happening?
Please help guys!!
Thanks in Advance…

Its hard to do without knowing what you’re doing in the container.

Maybe look into dockerfiles and create a “recipe” for your image, instead of doing commands IN a container for then to create a image of that.

I have tried running one simple flask service in the container of which workspace size is 8MB. How can this service increase the size of image?

but what did you install to run that flask service?
did you use apt-get update? on my debian, my apt cache is 400mb in size.

Yes I did.
I used some commands like:

apt-get update
apt-get upgrade
apt install python
pip install flask

Is that is the reason for getting the increased size of the docker image?
And if yes, then what should I do to control this. Because however, I need to use the above commands as those are must to run such workspaces in the docker container. I also have created one virtual environment in the docker.
And if yes, the installation of packages is making the big size image, then please help me out to do it properly without getting these type of issues.
Thanks for your reply and Support.

try and run a “apt-get clean” and see how much that helps

No, Nothing happened… :slightly_frowning_face:
It still very high sized… :cold_sweat:

I ran all the commands you mentioned, except for installing flask, as pip install was causing issues.

What i ran:

apt-get update
apt-get upgrade
apt install python
sudo apt-get install python-pip python-dev build-essential
sudo pip install --upgrade pip
sudo pip install --upgrade virtualenv

After committing, the image is around 500mb

Thanks for the response.
Means using apt for installing/updating packages causes the issue?
My docker image became 4GB in size, I’m not even storing much data into it. Should I stop using docker for the work then? or do we have any other solution to solve this?
Because without apt I cannot work in the docker. Can we have any other way to install such packages that will not cause the issue?

If i run

FROM python:2
RUN pip install flask

its 900mb.

I have no idea on how you can get it to 4gb :slight_smile:

I kept the docker container continuously running for many days

is it then maybe log files ?

Where and how to get that log file then?

Its pretty hard for me to tell you, since i dont know much about flask/your application.
But it was only a guess, maybe try and “cd /” and run “du -h --max-depth=1” and find out what it is that uses space

In General it is better to just define what you want to accomplish within a dockerfile.

When a container starts, all the differences to the image it’s running from will be part of the container runtime and will be included when you do a docker commit.

The increased size can have multiple reasons and is not limited to your flask application.

You can easily check the difference and probably the reason for the inflated image size with the docker diff {container_name}, which shows you exactly the differences.