What’s a Dockerfile?

Understand common Dockerfile instructions and how to combine them to write a Dockerfile.

There are two ways to create Docker images:

  1. We can create a Docker image by automatically building the image following the instructions in a text file called a Dockerfile.
  2. We can create a Docker image by modifying a running container content and committing the changes. It’s like taking a snapshot of a running container.

Making changes to a running container and committing the change to create a new image works well for some use cases. However, it’s more practical and effortlessly reproducible to use a Dockerfile.

Before we get started with a Dockerfile and creating a Docker image using the docker build command, let’s first define a Dockerfile.

Get hands-on with 1400+ tech skills courses.