3

I want to create a docker image with a few customizations. I have an existing image of 16GB and I have launched it as a container. Now I have deleted all the unnecessary files from the container and committed it as a new image. But the new image is still showing 16GB. Actually the new image should have only ~1GB in size.

How can I create a new small size image from a running container? Steps followed:

1) launched a container from the 16GB image
2) deleted unwanted files from the container
3) committed new image from the container 

Thanks sarath

b0gusb
  • 4,283
  • 2
  • 14
  • 33
SARATH CHANDRAN
  • 307
  • 1
  • 6
  • 16
  • 1
    Have you tried this https://docs.docker.com/engine/reference/commandline/commit/ – funnydman Jan 10 '19 at 06:20
  • 2
    you can export that using docker export or docker commit – Adiii Jan 10 '19 at 06:51
  • 2
    You can't just delete files from a large image to make it smaller. You can delete them, of course, and the filesystem will show that they aren't there *in the running container*, but they will still be there in the earlier layers where they were added. Have a read of [Dockerfile best practices](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/) – SiHa Jan 10 '19 at 08:38

1 Answers1

2

If you just need to reduce the size of the existing image, export it using docker export and then import it using docker import.

This question might also help.

b0gusb
  • 4,283
  • 2
  • 14
  • 33