Skip to content

aditya-suripeddi/dockerfile-best-practices

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dockerfile best practices

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

Following Dockerfile best practices will help in five areas:

1. Incremental build time

2. Image size

3. Maintainability

4. Security (pending)

5. Repeatability

Improving incremental build time:

1. Order matters for caching

2. More specific COPY to limit cache busts

Reduce Image size:

 1. Remove unnecessary dependencies
 
 2. Remove package manager cache

Maintainability:

1. Use official images when possible

2. Use more specific tags

3. Look for more minimal flavors

Reproducibility:

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

Running the java project in docker container

   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

Links to best practices

Improving Incremental build time

1-order-matters-for-caching

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

6-use-official-images

7-use-more-specific-tags

8-look-for-minimal-flavors

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

References:

  1. Intro-guide-to-dockerfile-best-practices

  2. Reference-slides-of-the-blog-above

  3. Github-dockerfile-best-practices-nodejs: the presentation format with different github branches is taken from this repository

  4. Dockerfile-best-practices

  5. Dockerdocs-dockerfile-best-practices

  6. Hexops-dockerfile-best-practices

About

dockerfile best practices on a java project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published