I was reading the Dockerfile Reference’s escape section. In the documentation, there is an example demonstrating how the default escape character ” may cause trouble in a Windows system.
FROM microsoft/nanoserver COPY testfile.txt c: RUN dir c:
PS C:John> docker build -t cmd .
Sending build context to Docker daemon 3.072 kB
Step 1/2 : FROM microsoft/nanoserver —> 22738ff49c6d
Step 2/2 : COPY testfile.txt c:RUN dir c:
GetFileAttributesEx c:RUN: The system cannot find the file specified.
According to my understanding, the first backslash in
COPY testfile.txt c: will escape the second backslash and the command becomes
COPY testfile.txt c:. The backslash disappears in the
RUN dir c: command because it works as an escape character, which makes sense. However, I’m not sure why the newline character is also escaped, as the COPY and RUN commands were merged into a single command. I’m not an expert in escape characters and I might misunderstand something very basic here. Can you please enlighten me how escape characters work in this scenario? Thanks in advance.