Search code examples
dockerlxc

Resize docker container after freeing space inside


I have a docker container with jenkins (let it be container1) - it is standard container run only with --privileged flag.

As part of CI process I am running containers inside this containers (for integration tests and so on). Everything worked nice - but I have decided to commit this container and founded that it's image (the result of commit) virtual size is ~140 Gb! And folder /var/lib/docker on the host (sudo du -sh /var/lib/docker) show's me 152 Gb

I logged in my container by sudo docker exec -i -t container1 and completely removed everything inside /var/lib/docker in container. I also run sudo du -sh / inside container1 and it showed only 32 Gb (which is normal - it is android SDK and other stuff). I tried to commit this container again - but results are the same ~ 140 Gb. So may be docker on the host were not able to reduce container size? Is there an way to say docker on the host that the container is almost empty and need to be shrunk

My docker info on host is:

  1. Containers: 5
  2. Images: 65 Storage
  3. Driver: aufs
  4. Root Dir:/var/lib/docker/aufs
  5. Dirs: 75
  6. Execution Driver: native-0.2 Kernel
  7. Version: 3.13.0-32-generic
  8. Operating System: Ubuntu 14.04.1 LTS

Solution

  • I made like was descried in "The Docker Book" by James Turnbull:

    VOLUME /var/lib/docker
    

    so all "heavy" stuff now is stored on host!

    Hope It will help somebody