

RUN -runs a command and creates an image layer. ENV - sets a persistent environment variable. A Dozen Dockerfile InstructionsįROM - specifies the base (parent) image. Let’s do a quick once-over of the dozen Dockerfile instructions we’ll explore. You can also used Windows-based images, but that’s a slower, less-pleasant, less-common process. In this article, I’m assuming you are using a Unix-based Docker image. Other instructions configure things, add metadata, or tell Docker to do something at run time, such as expose a port or run a command.

Only the instructions FROM, RUN, COPY, and ADD create layers in the final image. Instructions look like this: FROM ubuntu:18.04 COPY. Instructions are processed from top to bottom when an image is built. Each line in a Dockerfile can contain an instruction.

Docker is all about saving space and time by reusing existing layers.Ī Dockerfile instruction is a capitalized word at the start of a line followed by its arguments. When an image is pulled from a remote repository to a local machine only layers that are not already on the local machine are downloaded. A base image is also called a parent image. The base image provides the initial layer(s). In Unix, pretty much everything is a file. The Dockerfile tells Docker which layers to add and in which order to add them.Įach layer is really just a file with the changes since the previous layer. Each layer is read only, except the final container layer that sits on top of the others. Recall that a container is built from a series of layers. A different location can be specified with the file flag ( -f). The Dockerfile is assumed to be in the current working directory when docker build is called to create an image. The Dockerfile tells Docker how to build the image that will be used to make containers.Įach Docker image contains a file named Dockerfile with no extension. The Dockerfile is at the heart of Docker. The Docker image is created at build time and the Docker container is created at run time. It’s a self-contained, minimal operating system with application code. Recall that a Docker container is a Docker image brought to life.
