为什么docker上自己创建的mysql镜像特别大
巴扎黑
巴扎黑 2017-04-24 09:10:48
0
5
1336

新手刚入门,自己学着创建系统镜像和各种应用的镜像

我先自己制作了一个centos67的镜像,然后基于centos67装了vim,再docker commit 保存为centos67vim
然后再基于centos67vim上 编译安装了mysql5.6再commit保存为 mysql56,可是发现容量就达1.591GB了

我再docker pull mysql 发现为什么官方提供的只有360.3

多谢各位大大帮忙解答!!

巴扎黑
巴扎黑

reply all(5)
洪涛

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


Reference:

  1. mysql image analysis

  2. haron/vim analysis

  3. Centos basic image analysis

  4. 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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!