In the process of making the image, we should pay attention to a few points: 1. The file system is UnionFs, and each RUN in the Dockerfile will generate a layer. So we need to clean up the data generated after each RUN. Because the generated result (size of 3G) is a linear superposition of the sizes of each layer. 2. Why are official images generally too small? Let’s use mysql:5.6 as a reference to analyze:
RUN apt-get update && apt-get install -y perl --no-install-recommends && rm -rf /var/lib/apt/lists/* After updating the build, delete apt’s cached packages document. Generally speaking, this folder will occupy about 100M depending on the situation.
RUN { ...&& apt-get update && apt-get install -y mysql-server="${MYSQL_VERSION}" && rm -rf /var/lib/apt/lists/* && rm -rf / var/lib/mysql && mkdir -p /var/lib/mysql After installing db, delete the cached package files as usual. Deleting /var/lib/mysql can clear the sample database.
Let’s take a look at the most commonly used vim package in hub.docker.com. We found that the haron/vim image is 300M and uses scratch as the base image.
After a rough search on hub.docker.com, I couldn’t find a mysql image based on centos. Personally, I estimate that the problem is caused by the cached packages not being deleted.
As for the base image size issue mentioned by @ShawnTaoo brother, I also did the following investigation: centos:latest 190+MB, debian:jessie: 130+MB, ubuntu:latest 180+MB
You can check the dockerfile of the official image of mysql. The basic image should be different. In general, many official base images are very small. For example scratch, however, if you use an ubuntu or something, it will be about 180M (thanks to @ imdjh for correcting me). I haven’t noticed centos.
In the process of making the image, we should pay attention to a few points:
1. The file system is UnionFs, and each RUN in the Dockerfile will generate a layer. So we need to clean up the data generated after each RUN. Because the generated result (size of 3G) is a linear superposition of the sizes of each layer.
2. Why are official images generally too small? Let’s use mysql:5.6 as a reference to analyze:
Let’s take a look at the most commonly used vim package in hub.docker.com. We found that the haron/vim image is 300M and uses scratch as the base image.
After a rough search on hub.docker.com, I couldn’t find a mysql image based on centos. Personally, I estimate that the problem is caused by the cached packages not being deleted.
As for the base image size issue mentioned by @ShawnTaoo brother, I also did the following investigation: centos:latest 190+MB, debian:jessie: 130+MB, ubuntu:latest 180+MB
Reference:
mysql image analysis
haron/vim analysis
Centos basic image analysis
Ubuntu basic image analysis
No wonder I installed a lamp and one installation package only increased 3G. It turned out that one mysql increased by 1G
I haven’t started yet
It is recommended to read the introductory tutorial before playing
Commit without deleting the temporary files
You can check the dockerfile of the official image of mysql. The basic image should be different. In general, many official base images are very small. For example
scratch
, however, if you use an ubuntu or something, it will be about 180M (thanks to @imdjh for correcting me). I haven’t noticed centos.
If you can make your Dockerfile public, everyone can help you take a look. The main problem is the writing of Dockerfile