Parser Directives

Parser Directives are a special subset of optional comment lines in the Dockerfile. Any parser directives must occur before the first normal comment line. They must also precede any blank lines or other build instructions, including the FROM instruction. Basically, all parser directives must be at the very top of the Dockerfile. By the way, if you haven't figured it out yet, you can create a normal comment line in a Dockerfile by starting that line with a # character. The syntax for a parser directive is as follows:

# directive=value
# The line above shows the syntax for a parser directive

So, what can you do with a parser directive? Well right now, the only one supported is escape. The escape parser directive is used to change what character is used to indicate that the next character in the instruction is to be treated as a character and not as the special character it represents. The default value if no parser directive is used is . You have seen this used in several examples throughout this chapter to escape the newline character, allowing for instructions to be continued onto the next line in the Dockerfile. If it is necessary to use a different escape character, you can use the escape parser directive to handle that. You can set the escape character to one of two choices:

# escape= (backslash)
Or
# escape=` (backtick)

One example where you might want to change the character used as the escape character is when you are creating a Dockerfile on Windows systems. As you know, the  is used to distinguish folder levels in path strings, such as c:windowssystem32
drivers
. Switching to the backtick for the escape character will avoid needing to escape such strings as this: c:\windows\system32\drivers.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset