商道如狼道 发表于 2025-3-6 23:54:06

【MySQL】用MySQL二进制包构建docker镜像

一、实行配景

   【MySQL&docker】基于CentOS7.5 编译制作MySQL5.7.28镜像
   https://www.jianshu.com/p/71fd79b69a6b
                     https://i-blog.csdnimg.cn/img_convert/6228f8510f7960bf0db06a1ec40444d9.webp?x-oss-process=image/format,png                   用MySQL源码编译的docker镜像,体积过大,直奔3G了,你也不清晰,这点编译参数打出的体积怎么就这么大!
   想到MySQL官方提供一种二进制安装包,只有600M左右,加上基础镜像和一些依赖包,打成镜像的话,也就1G大一点。
   

                     https://i-blog.csdnimg.cn/img_convert/6e05c1037f2924d1081c74f889acb8e8.webp?x-oss-process=image/format,png                  

   二、下载MySQL二进制安装包

   

   官网地址:https://dev.mysql.com/downloads/mysql/5.7.html
   # wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
   

                     https://i-blog.csdnimg.cn/img_convert/034ae915a6839fd2501e04a4d20621a4.webp?x-oss-process=image/format,png                  
   
   # tar -zxf  mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
   # cd  mysql-5.7.28-linux-glibc2.12-x86_64  
   
                     https://i-blog.csdnimg.cn/img_convert/47245ec942d777211e500f8cbc198ac1.webp?x-oss-process=image/format,png                   看来失算了,600M是压缩包的大小,解压后就2.7G了!
                     https://i-blog.csdnimg.cn/img_convert/763eb357140cd47017c8c4628d8dc3cf.webp?x-oss-process=image/format,png                                       https://i-blog.csdnimg.cn/img_convert/18112bcda62ea61e1f8f097a9d0eb32a.webp?x-oss-process=image/format,png                  

   

   MySQL 官方镜像中二进制文件个库文件的体积大小,我们以 MySQL 5.7.27 为例:
   # docker run -it --rm mysql:5.7.27 bash
   # du -sh /usr/bin/mysql*
   # du -sh /usr/sbin/mysql*
   # du -sh /usr/lib/mysql/
   

                     https://i-blog.csdnimg.cn/img_convert/18c239bd69b4fce914a0d1c4d128cecb.webp?x-oss-process=image/format,png                  

   现在知道为什么MySQL官方镜像为什么小了,因为只安装必须的一下二进制文件和库文件,而编译安装和二进制包是将所有的二进制文件和库文件都包括了!
   假如想缩小构建的编译的镜像体积,就须要清晰怎么取舍二进制问文件和库文件了!
   

   官方Dockerfile:
   dockerfile:https://github.com/docker-library/mysql/blob/master/5.7/Dockerfile
   docker-entrypoint.sh:https://github.com/docker-library/mysql/blob/master/5.7/docker-entrypoint.sh
   

   三、参考

   

   MySQL5.7 Dockerfile
   https://www.cnblogs.com/wshenjin/p/10100949.html
   

   简仿MySQL官方容器dockerfile
   https://blog.csdn.net/weixin_33981932/article/details/92600770
         ©    著作权归作者所有,转载或内容合作请接洽作者   
https://img-blog.csdnimg.cn/direct/67c64049147741939b85489caefbb597.png
喜欢的朋友记得点赞、收藏、关注哦!!!

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: 【MySQL】用MySQL二进制包构建docker镜像