Image size is the storage space required by a container image. Monitoring it helps reduce the space used by a Docker application and guides choices between standard, slim, and Alpine images. section 3.6.2
Reduce image size by:
- Inspecting current images with docker image ls. section 3.6.2
- Choosing slim images when the Dockerfile depends on Debian tools such as apt-get. section 3.6.2
- Using Alpine images when required software supports musl libc, BusyBox, and apk, then testing compatibility. section 3.6.2
- Keeping Dockerfile layers minimal and cleaning temporary files in the same layer that creates them. section 3.6.3
Comparing container image sizes
A Docker application starts with a 1.09 GB API image, a 417 MB Postgres image, and a 187 MB web image. Switching Postgres to Alpine reduces it to 239 MB, switching the web image reduces it to 42.6 MB, and replacing the API base image with slim reduces it to about 557 MB. section 3.6.2
dockercompose7-web latest 9d0257a0f9b0 About an hour ago 187MB postgres latest e872544a957a About an hour ago 417MB dockercompose7-api latest 5a2bb8fc1b02 24 hours ago 1.09GB cloudbeaver latest 9b672f480fc7 2 weeks ago 250MB
Use the image listing to compare container sizes before changing base images or Dockerfile instructions. section 3.6.2

