Issue
I have recently started working on docker and I am trying to build a custom image for CentOS using CentOS:7.5.1804 image.
The problem I am facing here is that the original CentOS:7.5.1804 image is showing size 200MB and after I add the desired packages, the size of image becomes 1.2 GB! I am trying to figure out if there is a way to reduce the image size?
I tried using yum clean all
& rm -rf /var/cache/yum
in my dockerfile, however it barely reduced few MBs and it didn't helped much.
Any inputs/suggestions/best practices to reduce image size are welcome. My docker file is as shown below, which results into a 1.2GB image!
#Use CentOS as base
FROM centos:7.5.1804
# Docker recommends
RUN yum -y update && yum clean all
# Install custom tools
RUN yum -y install openssl && yum install -y nc && \
yum -y install python3 && pip3 install j2cli && \
yum -y install epel-release && yum -y update && yum install -y ccrypt && \
yum clean all && rm -rf /var/cache/yum
Solution
You have some unnecessary instructions, Could you try with this Dockerfile?
#Use CentOS as base
FROM centos:7.5.1804
# Install custom tools
RUN yum -y install openssl ccrypt nc epel-release python3 && \
pip3 install j2cli && \
yum clean all && rm -rf /var/cache/yum
Answered By - kevs Answer Checked By - Clifford M. (WPSolving Volunteer)