This repository is a guide with a set of good practices when writting Dockerfiles.
Using a Node.js application as example, this guide will be a journey from a very basic Dockerfile to make it production ready, describing some of the best practices and common pitfalls that you are likely to encounter when developing Dockerfiles.
On this blog post you'll find detailed information about each of the steps we'll do to improve the Dockerfile. Please use it to follow this tutorial.
Note: the blog post was published on February 2019. There are corrections and updates only available on this GitHub repository.
Use BuildKit to build your Docker images. It can improve the performance when building Docker images.
It can be enabled on two different ways:
- Exporting the
DOCKER_BUILDKIT
environment variable:
export DOCKER_BUILDKIT=1
TIP: add it to your ~/.bashrc file
- Configuring the Docker Daemon to add the Buildkit feature:
{
"features": {
"buildkit": true
}
}
A Linter helps you to detect syntax errors on your Dockerfiles and provides you suggestions based on common practices.
There are plugins that provide these functionalities for almost every IDE. Here you have some suggestions:
- Atom: linter-docker
- Eclipse: Docker Editor
- Visual Studio: Docker for Visual Studio Code
Starting from the 'master' branch, you'll find a branch with the files to use on each step of the tutorial.
It's only necessary to switch (checkout) to the proper branch. The available branches are: