Dockerfile
An image is defined using a Dockerfile
. A Dockerfile
is human readable text file with a list of steps that describe how to build the image, such as
configure the system
copy the application files
install the required dependencies
set the working directory
running command in the container
setting environment variables
exposing ports in the container
Common Dockerfile instructions
The table below lists the most common used instructions for a Dockerfile.
An example of a Dockerfile
Dockerfile
Below is an example of a Dockerfile used to setup a Ruby on Rails application.
Note that the order of the instructions does play a significant role when creating a Dockerfile
. During the process of building an image Docker steps through the instructions in your Dockerfile
executing each in the order specified. As each instruction is examined, Docker looks for an previous generated intermediate image in its cache that it can reuse, rather than creating a new (duplicate) image. This means that your build stage layers (created by most Dockerfile
instructions) should be ordered from the less frequently changed to the more frequently changed allowing maximum use of cached images, and speeding up building times immensely.
Last updated