The aim of the repository is to understand some of the best practices for writing a Dockerfile for a java maven project hands on as discussed in dockerfile-best-practices
A better Dockerfile is written as you go from master branch to 1-order-matters-for-caching till you reach 11-multi-stage-builds-to-remove-build-deps
The idea of using git branches for presenting the outcome of each applied best practice is taken from Github-dockerfile-best-practices-nodejs
The master branch also has a python flask rest app to practice writing Dockerfile for a python project
1. Incremental build time
2. Image size
3. Maintainability
4. Security (pending)
5. Repeatability
1. Order matters for caching
2. More specific COPY to limit cache busts
1. Remove unnecessary dependencies
2. Remove package manager cache
1. Use official images when possible
2. Use more specific tags
3. Look for more minimal flavors
1. Line buddies: apt-get update & install in singe RUN statement?
2. Build-from-source in a consistent environment
3. Fetch dependencies in a spearate step
4. Use multi-stage builds to remove build dependencies
Install docker and run the docker daemon
$ sudo dockerd &
Clone the repository
$ git clone https://github.com/aditya-suripeddi/dockerfile-best-practices.git
Go to the project directory
$ cd dockerfile-best-practices
Build the container image
$ docker build -t java-app .
Run the container
$ docker run java-app
Improving Incremental build time
2-more-specific-copy-to-limit-cache-busts
Reproducibility?
3-line-buddies-apt-update-install
Reduce Image Size
4-remove-unnecessary-dependencies
5-remove-package-manager-cache
Maintainability
Reproducibility
9-build-from-source-in-consistent-environemnt
Improving Incremental build time?
10-fetch-dependencies-in-a-separate-step
Reduce Image Size? multi-stage-builds-reduce-image-size
11-multi-stage-builds-to-remove-build-deps
-
Github-dockerfile-best-practices-nodejs: the presentation format with different github branches is taken from this repository