Dockerfile

Published: Friday, 3 July 2020
By:
  • Jurn Ho

A Dockerfile is a list of steps used to build an image.

It can be stored with build scripts of an application.

Each line in the Dockerfile is a step that docker will execute when building the image.

The first line is usually a FROM

Instructions

Each line of a Dockerfile can contain instructions that will incrementally build the image.

FROM

FROM httpd:2.4

FROM will start the image from the specified base or parent image. If there are no more instructions following, then the build image will be the same as the base image.

COPY

FROM httpd:2.4
COPY ./public/ /usr/local/apache2/htdocs/

COPY will copy from the local file system to the image file system.

Building

The docker client can build the image and store it on the server.

To build an image using the Dockerfile in the current directory, run docker build .

$ docker build .
Sending build context to Docker daemon  2.048kB
Step 1/1 : FROM httpd:2.4
 ---> b2c2ab6dcf2e
Successfully built b2c2ab6dcf2e

It will give feedback on each step of the Dockerfile.

Give your image a tag via using the --tag option.

$ docker build . --tag magicmonster/example
Sending build context to Docker daemon  2.048kB
Step 1/1 : FROM httpd:2.4
 ---> b2c2ab6dcf2e
Successfully built b2c2ab6dcf2e
Successfully tagged magicmonster/example:latest

In the above the example the image name is magicmonster/example and tag is magicmonster/example:latest.

References