FROM centos:centos7.4.1708 RUN cd /etc/yum.repos.d/ && curl -sO http://mirrors.163.com/.help/CentOS7-Base-163.repo && mv ./CentOS-Base.repo ./CentOS-Base.repo.backup && mv ./CentOS7-Base-163.repo CentOS-Base.repo && yum clean all && yum makecache && yum -y install openssh openssh-server && echo 123456 | passwd --stdin root
docker build -t z/centos7.4:ssh . docker images # Results z/centos7.4 654MB centos7.4.1708 197MB
Excuse me, why is the yum source updated and ssh installed?From 197M to 654M?How to reduce the volume?
This is because the cache of yum source is relatively large. docker not only saves yum source but also saves version information like git/svn. The more instructions you use in Dockerfile, the larger the version library will be. Docker is only a container, not a virtual machine, so in most cases, it is only used as a running environment, not a development environment. Therefore, after the software is installed, the source and the dependency package need to be deleted during compilation to reduce the volume. In most cases, centos will be larger than ubuntu, but at least it will be tens of meters larger. Now there are rumors that docker officials will use alpine instead of ubuntu as the default mirror, because a bare alpine is only about 5 meters, which is much smaller than centos and ubuntu. It is recommended that you look at some official image tag, many of which have alpine versions, such as php.https://hub.docker.com/_/php/, you can look at the official Dockerfile, also through the installation of relevant software, delete the source and unnecessary dependency package to minimize the volume