Write a Good Dockerfile in 0 Steps

If you already have the Pack CLI installed, you can create a Docker image for any Java, Node.js, Python, or Ruby app (without a Dockerfile) by running:

$ pack build --builder heroku/buildpacks:20 my-app

Or with Spring Boot, you can run the following command (which uses the Paketo Buildpacks):

$ ./mvnw spring-boot:build-image

Both of these commands will create a well-structured Docker image that has several advantages over one you create with a Dockerfile, including:

  • It can be rebased (i.e. the operating system can be updated in milliseconds without a re-build)
  • The cache won’t be unnecessarily invalidated because lower layers changed.
  • You can combine multiple language runtimes without copy-pasting from other Dockerfiles
  • It can have multiple entrypoints for each operational mode
  • Reproduces the same app image digest by re-running the build
  • Includes a bill-of-materials describing the contents of the image

If you still want or need to write a Dockerfile, see my previous post on Writing a Good Dockerfile in 19 steps