Skip to content

Public repository dedicated to guide the use of multi-stage and distroless dockerfile examples in docker, or other containers technologies, with the objetive to create secured templates for new developments

Notifications You must be signed in to change notification settings

pabpereza/dockerfile-best-practices

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Curated Dockerfiles examples

This repository contains examples of Dockerfiles using the best practices that docker recommends. This approach allows to build a Docker image with a minimal footprint, by copying only the necessary files from the build stage to the final image and using non-root user to run the application.

For more information about multi stage builds, please refer to the official documentation.

Best practices and security checks

  • Use a lightweight image.
  • Minimun number of layers.
  • Optimize build order.
    • Install OS packages and dependencies first (cache in another image).
    • Copy library definitions first, then build.
  • Multi-stage.
    • Avoid compilers.
    • Avoid caching the build process.
  • Avoid using the root user.
  • File permissions (when copying from the builder).
  • Sort multi-line arguments.
  • Exclude with dockerignore.

Examples by language or technology

How to use these examples

Each example contains a Dockerfile and Dockerfile.old. The .old file contains simple Dockerfile without multi stage builds and the Dockerfile contains the multi stage build version.

To build the image, you can use the following command:

docker build -t <image_name> .

If you want to build the image using the old Dockerfile, you can use the following command:

docker build -t <image_name> -f Dockerfile.old .

To run the image, you can use the following command:

docker run -it <image_name>

How contribute to this repository

If you want to contribute to this repository, please follow these steps:

  1. Fork this repository
  2. Add your example in a new folder or update an existing example (always grouped by language or technology). This example must to contain a curated dockerfile and an old version called "dockerfile.old" to exemplify the less optimized version.
  3. Create a pull request with your changes

About

Public repository dedicated to guide the use of multi-stage and distroless dockerfile examples in docker, or other containers technologies, with the objetive to create secured templates for new developments

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published