Docker image larger than its filesystem

I have a docker image that I built from several layers and a debian:jessie base image that I’m working on making smaller. I added a cleanup layer than does apt-get remove a bunch of packages and deletes files from the filesystem. When I run the resulting image and do du -h inside it I can see it’s about 1.3GB. However, when I look at the image size in docker images, it’s more than 2.2GB, which is the size of the image before the cleanup layer. Why is the final image not getting smaller?

  • docker-compose up container start ordering
  • How to setup docker-machine to be as default?
  • Can't connect to Amazon RDS from Docker container
  • new docker container for every user
  • Docker map drive from Docker container to Linux to Windows host
  • NodeJS & Docker: How to change the default Context an App is under: e.g. /myapp/stuff rather than /stuff
  • Permission denied when running a container (docker 1.12.5)
  • Restoring to a neo4j docker container
  • How could I get files from a docker container running the official etcd image if there is no shell?
  • Unable to push my docker to Bluemix - Login error
  • Docker/Jupyter notebook setting Base URL
  • Prevent request too quickly in bash
  • One Solution collect form web for “Docker image larger than its filesystem”

    You can’t have a cleanup layer – the Union File System doesn’t work like that. If files exist in layer 1, and you delete them in layer 2, all Docker does when you run the container is hide the deleted files. Once files are saved into an image layer, they can’t be removed from that layer.

    You can try using the Docker squash tool to reduce the final image size, or rework your Dockerfiles in line with Titouan Freville’s comment – do all the APT commands in one RUN statement (update, install remove). That way when the image layer is saved, the files have already been cleaned up.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.