Current location - Health Preservation Learning Network - Healthy weight loss - Docker's image is too big, how to get smaller?
Docker's image is too big, how to get smaller?
You can experience the above dialogue slowly. But in any case, for students who have embraced SSD, it is absolutely unacceptable to store 50 Docker images with a size of about 800MB on precious SSD! ! But most of the pictures downloaded from Docker Hub are this number, even much larger than this number. Seeing that the disk space was gradually eroded by Docker, the landlord decided to slim down the Docker file. Facts have proved that the effect is remarkable. Please look at the picture below.

Tremble, mortal! 100MB of Redis is compressed to only 7MB! ! !

First, correct the basic concepts:

1.Docker is not a virtual machine (remember)

2. The program in 2.Docker does not need a complete operating system when running!

3. Corios, RHEL, Ubuntu, CentOS, etc. , is an operating system!

How to do it is basically the following steps.

1. Use Busybox's Install command to create a minimized system environment.

2. Delete all kinds of unnecessary system files, which are unnecessary, and then need specific program analysis. The landlord spent a lot of time analyzing each program, and now the landlord can almost recite the dependencies of these apps backwards.

3. Pack these documents to rootfs.tar?

4. Use the ADD instruction of Dockerfile to generate an image with rootfs.tar.

The landlord stopped coding and started coding.

1. Based on Redis 2.8. 13, the simplest rootfs.tar is generated.

Dockerfile file

2. Use this rootfs.tar to generate the smallest Redis image file.

Dockerfile file

Step 3 give it a try

docker run-RM-it-p 6379:6379 microbox/redis

The image generated by this method is no different from the ordinary redis image. Enjoy it, the landlord has already released 30GB of space first.