Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiline comments in Dockerfiles

Is there a fast way to comment out multiple lines in a Dockerfile?

I know that I can add # at the beginning of each line. But if there are many lines this is too much work. In some languages there are multiline comments such as /* ... */, which makes commenting out large parts of a file very fast.

like image 465
user1460043 Avatar asked Mar 14 '19 15:03

user1460043


People also ask

Can Dockerfiles have comments?

Like programming languages, you can write comments in your Dockerfiles. Comments in Dockerfiles are denoted by using the hash or pound symbol # at the beginning of the line. You should note that it only supports one-line comments, hence to write multi-line comments, you'll use the hash symbol on each line.

How do I comment in Dockerignore?

If a line in . dockerignore file starts with # in column 1, then this line is considered as a comment and is ignored before interpreted by the CLI.

What is Multiple comment?

Multiline comments are used for large text descriptions of code or to comment out chunks of code while debugging applications. Comments are ignored by the compiler.


1 Answers

As of today, no.

According to Dockerfile reference documentation:

Docker treats lines that begin with # as a comment, unless the line is a valid parser directive. A # marker anywhere else in a line is treated as an argument.:

There is no further details on how to comment lines.

As said by some comments already, most IDE will allow you to perform multiline comments easily (such as CTRL + / on IntelliJ)

like image 117
Pierre B. Avatar answered Sep 18 '22 17:09

Pierre B.