新手刚入门,自己学着创建系统镜像和各种应用的镜像
我先自己制作了一个centos67的镜像,然后基于centos67装了vim,再docker commit 保存为centos67vim
然后再基于centos67vim上 编译安装了mysql5.6再commit保存为 mysql56,可是发现容量就达1.591GB了
我再docker pull mysql 发现为什么官方提供的只有360.3
多谢各位大大帮忙解答!!
PHP中文网2017-04-24 09:12:48
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.
mysql image analysis
haron/vim analysis
Centos basic image analysis
Ubuntu basic image analysis
ringa_lee2017-04-24 09:12:48
No wonder I installed a lamp and one installation package only increased 3G. It turned out that one mysql increased by 1G
迷茫2017-04-24 09:12:48
I haven’t started yet
It is recommended to read the introductory tutorial before playing
Commit without deleting the temporary files
怪我咯2017-04-24 09:12:48
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.
阿神2017-04-24 09:12:48
If you can make your Dockerfile public, everyone can help you take a look. The main problem is the writing of Dockerfile