right now I’m experimenting with Docker.
I have "installed" a Docker Debian Image.
In this Debian Environment, I installed a application.
Now, I do every night this:
- docker stop (stop container)
- docker commit (make container to an
image) - docker save (to save the image to an file, I do this to backup
the current work) - docker run (to start the container)
So as you can see, I try to create a "backup-solution".
It works perfectly. But the problem is, that the backup-files are getting bigger and bigger by every day.
Even without touchting the container for multiple days.
It used to be well under 10 gigabytes, but now it’s already 20.
Why is that? What am I doing wrong?
Thanks a lot
3
Answers
Docker images save "diffs" every commit you make, along with all previous versions of your image. This means that your process is guaranteed to steadily increase your final image size. To avoid this, instead of using
docker save
, you should usedocker export
instead (which receives the container as an argument, instead of an image).Docker save
Docker export
Using
docker commit
usually isn’t a best practice. The Dockerfile system described in places like Docker’s Build and run your image tutorial will let you write a file that lists out all of the commands that need to be run to build the image. You can check that file into source control, and rundocker build
whenever you need to recreate the image.If the
Dockerfile
is checked in alongside the source code to your application, you can check out old versions of your application source and re-docker build
the image from there. There’s not a particular need to save binary copies of images.At a technical level, the images
docker commit
creates always consist of the original image, plus an additional layer that’s whatever changed in the container. If you repeatedlydocker commit
each image will always be larger than the image before it, even if you delete or overwrite files. (Typical Docker images are under 1 GB, and depending on the application runtime and base image, are frequently in the 100-200 MB range.)I had the same problem until I figured out it’s because after
docker save
the imagetar
file was generated in the same folder.Next time when it’s built again, the
tar
file is included inside the next image as well.After added
*.tar
in my.dockerignore
now it’s working fine.