Dockerfile is used to configure docker images and specify commands to be executed before the image creation. Dockerfile contains instructions to read by the docker engine and executed properly. Even the Dockerfile may contain a lot of commands, configuration, etc. which should be explained and described for later use. Comments can be added into a Dockerfile to explain and describe different configurations and commands.
Dockerfile Singleline Comment
Singleline comments can be create by using the hash mark
at the start of the lines in Dockerfile. These comment lines are not interpreted as command or not executed. The hash mark should be located at the start of the line to mark the whole line as comment.
# Use Ubuntu 18.04 image as base
FROM ubuntu:18.04
# Copy the app folder
COPY . /app
#Compile the app
RUN make /app
# Execute app.py
CMD python /app/app.py
Dockerfile Mulitiline Comment
Dockerfile does not provide district multiline comments. The single-line comment sign, hash mark, can be used to create multiline comments in Dockerfile. Just put multiple lines of comments one after the others. This creates a multiline comment.
# This dockerfile is created to compile and run
# application named myapp
# You can also use different Linux distributions
# than Ubuntu.
# Use Ubuntu 18.04 image as base
FROM ubuntu:18.04
# Copy the app folder
COPY . /app
#Compile the app
RUN make /app
# Execute app.py
CMD python /app/app.py