Skip to content

dockerfile: fix heredoc parsing with space after modifier#6822

Open
kasperk81 wants to merge 1 commit into
moby:masterfrom
kasperk81:patch-1
Open

dockerfile: fix heredoc parsing with space after modifier#6822
kasperk81 wants to merge 1 commit into
moby:masterfrom
kasperk81:patch-1

Conversation

@kasperk81

Copy link
Copy Markdown

Fix this case: #5778 (comment)

Signed-off-by: kasperk81 <83082615+kasperk81@users.noreply.github.com>
@kasperk81

Copy link
Copy Markdown
Author

this works

FROM alpine:3.22
RUN cat <<-EOF > /hello.txt
hello
EOF

RUN cat /hello.txt

this too:

FROM alpine:3.22
RUN cat << EOF > /hello.txt
hello
EOF

RUN cat /hello.txt

but this was failing with dockerfile parse error on line 3: unknown instruction: hello:

FROM alpine:3.22
RUN cat <<- EOF > /hello.txt
hello
EOF

RUN cat /hello.txt

@thaJeztah

Copy link
Copy Markdown
Member

this works

FROM alpine:3.22
RUN cat <<-EOF > /hello.txt
hello
EOF

RUN cat /hello.txt

this too:

FROM alpine:3.22
RUN cat << EOF > /hello.txt
hello
EOF

RUN cat /hello.txt

Both of those are expected to fail, because there's no Dockerfile here-doc used, so they're line-terminated;

This is the Dockerfile RUN instruction;

RUN cat << EOF > /hello.txt

And hello and EOF are parsed as separate Dockerfile instructions, which are invalid

@thaJeztah thaJeztah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look correct (see my comment); it's conflating here-docs used in a shell with here-docs provided by the Dockerfile parser.

@kasperk81

Copy link
Copy Markdown
Author

Both of those are expected to fail, because there's no Dockerfile here-doc used, so they're line-terminated;

they both work, do you mean that's a bug that they aren't failing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants