最小化基于CentOS的Docker镜像

我build立了一个基于CentOS镜像的PHP-FPM镜像

FROM centos:7 RUN yum -y install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm && \ yum -y install php-fpm php-mysqlnd php-mbstring php-intl php-amqp php-redis php-opcache --enablerepo remi,remi-php56 && \ groupadd -g 1000 nginx && \ useradd -u 1000 -g 1000 nginx EXPOSE 9000 CMD ["php-fpm", "-F"] 

并意识到最终的图像相当大(超过350MB)。 请告诉我在哪里可以删除不需要的文件在Docker Hub上的一些基于Debian的图像?

 rm -rf /var/lib/apt/lists/* rm -rf /var/lib/mysql 

感谢您的帮助!

你可以用yum clean all yums cache,像这样:

 RUN yum -y install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm && \ yum -y install php-fpm php-mysqlnd php-mbstring php-intl php-amqp php-redis php-opcache --enablerepo remi,remi-php56 && \ groupadd -g 1000 nginx && \ useradd -u 1000 -g 1000 nginx && \ yum clean all 

这节省了大约70 MB。

如果这还不够,可以考虑使用BusyBoxAlpine等不同的基本图像。

Centos已经有大约170 MB了

您可以在“remi-safe”存储库(并使用/ opt / remi / php56 / root / usr / sbin / php-fpm命令)中使用SCL软件包(php56-php *)。

虽然php- *软件包同时提供了NTS和ZTS(线程安全)版本,但是php56-php- *软件包只提供标准的NTS版本(在你的情况下不需要ZTS版本),所以更小。

真的不知道你会省多less钱。