-
Notifications
You must be signed in to change notification settings - Fork 66
Docker file cleanups #16
Description
I have a bunch of proposals for cleaning up the Docker file. I don't want to simply fork it again without pushing upstream, so I'm ready to discuss before doing so. If you agree with the individual changes, I'll provide a pull request at some time in the future.
Reducing the Number of Layers
Each invocation of RUN in a Dockerfile results in a new layer generated, which is both overhead at runtime and will persist all space that layer consumed forever. Especially, running clean-up tasks like yum update in an additional RUN command will not have the desired effect of reducing the image size, but adding another layer which lists the deleted files.
The image should limit to a smallest possible number of layers, especially merging most of the RUN yum ... invocations to a single one with cleaning performed as last step, like
RUN yum -y -q install zabbix22-dbfiles-mysql \
yum -y -q install monit \
yum -y -q install sudo \
yum clean all && rm -rf /tmp/*
(but for all the package installation steps), so temporary files and similar stuff is removed before persisting the layer.
Similarlly, multiple ADD [src]... [target] invocations can be merged to a single one, if all pointing to the same target.
RUN chmod for files added from the git repository should better be performed already in the repository, since permissions are adopted.
Upgrading the Base System
The base system should not be upgraded unless there is very good reason. The (official) base images are updated regularly anyway, so it should not be required to run:
# Update base images.
RUN yum distribution-synchronization -y
Installing tools not required for running the application itself is also discouraged, as making the image larger and providing a larger attack surface.
Management Tools
Are these tools required? Especially vim will not be. If required, the administrator can easily and quickly add it (and drop it again afterwards, or even drop the whole image).
# Additional Tools
RUN yum -y -q install passwd perl-JSON pwgen vim
LInking Repositories
Not directly related to the Dockerfile, but to the build process: to receive security and bug fixes, the Image should be rebuild on updates of the base system. This is possible by using the "Linked Images" feature of the Index website.