- When using alpine as a base image, use
apk --no-cache add
for packages... don't ever useapk update
orapk upgrade
— this just causes the repo database to be populated and add wasted space to an image. Additionally, if using Debian/Ubuntu, since you have to do aapt-get update
first before installing, at the end of installation of packages, do arm -rf /var/lib/apt/lists/*
to clean up the apt lists. - If you're going to add something for one step and never use it again, use && to merge the steps. For instance:
apk --no-cache add git && git clone ${giturl} && apk --no-cache del git
- Combine steps, but don't just throw EVERYTHING on one RUN command. It's ugly. If you do combine steps, make use of
\
at the end of a line and&&
at the beginning of the next line (preferably indented to line up to the commads) to keep things neat. - If you have a weird
sed -i "s/nothing.com/example.com/g" file.html
line or similar that appears to do something that isn't a standard inst