×
☰ See All Chapters

Docker dockerfile

In the previous chapter, we explained in few lines about docker file. In this chapter you will learn in detail to build Docker images using Dockerfile. A Dockerfile is simply a plain text file that contains a set of user-defined commands, which when executed by the "docker image build" command to build the docker image.

The commands inside the Dockerfile can include the base image selection, installing the required application, adding the configuration and the data files, and automatically running the services as well as exposing those services to the external world.

Syntax of docker commands/instructions

Below is the syntax of docker command:

COMMAND arguments

Example:

FROM alpine:latest

FROM is a command

alpine:latest is the argument

  • Each command begins with the instruction itself, which is followed by the arguments for the command. 

  • Each command should be written in new line. 

  • Command and arguments can be written in any case. Whole dockerfile commands are case-insensitive. But it is convention to write COMMAND in uppercase and arguments in lowercase. 

  • If command is lengthy, you can split the command to multi lines using \ as shown below: 

RUN apk add --update nginx && \

rm -rf /var/cache/apk/* && \

mkdir -p /tmp/nginx/

Comments in docker file

  • You can add comments in docker file, the comment line in Dockerfile must begin with the # symbol. # Symbol should be the very first character in that line. 

  • If the # symbol is preceded by a whitespace, then the docker build system would consider that as an unknown instruction and skip the line. 

  • If the # symbol is used after command then # will be treated as argument to that command. 

docker-dockerfile-0
 

Docker commands/instructions

Checkout our Docker commands/instructions tutorial from here Docker Command

 


All Chapters
Author