-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HERE-DOC syntax issue when a line contains a dockerfile directive in CMD #5240
Comments
Thanks for reporting; looks indeed that som other parsing picks this up; docker build --progress=plain --no-cache -<<'EOF'
# syntax=docker/dockerfile:1
FROM alpine
RUN -<<'EOT'
env
EOT
EOF
moby/moby#1 [internal] load build definition from Dockerfile
moby/moby#1 transferring dockerfile: 100B done
moby/moby#1 DONE 0.0s
moby/moby#2 resolve image config for docker-image://docker.io/docker/dockerfile:1
moby/moby#2 DONE 0.5s
moby/moby#3 docker-image://docker.io/docker/dockerfile:1@sha256:fe40cf4e92cd0c467be2cfc30657a680ae2398318afd50b0c80585784c604f28
moby/moby#3 resolve docker.io/docker/dockerfile:1@sha256:fe40cf4e92cd0c467be2cfc30657a680ae2398318afd50b0c80585784c604f28 0.0s done
moby/moby#3 CACHED
1 warning found (use docker --debug to expand):
- ConsistentInstructionCasing: Command 'env' should match the case of the command majority (uppercase) (line 5)
Dockerfile:5
--------------------
3 | FROM alpine
4 | RUN -<<'EOT'
5 | >>> env
6 | EOT
7 |
--------------------
ERROR: failed to solve: dockerfile parse error on line 5: ENV requires at least one argument
Let me more this ticket to the BuildKit repository, which is where the code is maintained for parsing the Dockerfile. |
@daghack Looks like consistent-casing check just walks all top-level AST https://github.com/moby/buildkit/blob/v0.15.1/frontend/dockerfile/dockerfile2llb/convert.go#L2214-L2228 . It needs to be smarter to detect the nodes that were part of the heredoc of the previous command. Probably this check should happen after |
@tonistiigi PR PR that address your comment. To clarify, it does not fix this issue, which has to do with the actual parsing, rather than the checks around the parsing, but does address the issue of the check operating at the AST level, which is less than ideal. |
I'm confused now. What is |
Ugh. That's my mistake 🙈 I must've added the |
@EatPrilosec Are you able to give us an example Dockerfile, whether your original case or a simple reproduction, for this issue? |
here is an old commit where i was first experiencing the issue. if you fork, there should be a github workflow action to build the docker, just mentioning for convenience edit: in fact, heres the workflow run for that commit :) https://github.com/EatPrilosec/epg-cron-docker/actions/runs/10342066164/job/28624575134 (PS, the docker version and environment that i provided was for my pc, not githubs runner) |
I notice the HereDoc end marker is not at the start of the line (has leading white space); wondering if that's related here; https://github.com/EatPrilosec/epg-cron-docker/blob/1d1d6ad2f19308a8ae5fc1157e06078784cc7141/Dockerfile#L105 |
i believe i checked this, let me look through the commits |
yea, here i used EOF for troubleshooting and here was before i even added indents -- i thought the LACK of indents was the issue at the time PS sorry for not providing these earlier, slipped my mind at the time. and thanks for taking a look! |
Wait, really? Now that suprising because it failed for the GitHub runner AND locally (on my PC) for me. you're telling me that the docker file(s) I provided, build? And just to ask the dumb question, you cloned one of the commits I provided and not the current right? Current doesn't have the heredoc. Assuming you didn't clone head, my gut says line endings, just to throw my two cents in there. But they should all have been |
I don't think it's the syntax / formatting there; I noticed the Dockerfile example uses heredoc for So in that case it will likely see the Not sure why it errors on the |
Reviewed what I was testing, and I was absolutely incorrect there, good callout! At some point in the testing, I had replaced the Digging into this to find out what's happening and how we can make it better/easier to understand what's failing in the future! |
now that makes more sense. and now that the distinction has been pointed out, i think what happened is, while trying to format my complex the second sentence: " which then led me to heredocs in shell form documentation. https://docs.docker.com/reference/dockerfile/#shell-form this led me to misinterpret that however i'd vote for here-doc support in PS: sorry for the confusion, ive updated the github issue to reflect the true problem |
It looks like what's happening is that because Ultimately, it seems like the behavior we might want is that if a user uses heredoc syntax with an unsupported command, we produce an appropriate error.
Ah! Well, that's definitely an issue! |
this might also explain while double checking just now, on my local linux server which appears to have an older docker engine, it errors out on
id also like to, as a user, take this opportunity to stress my vote for supporting heredocs in |
Seems like a reasonable position — it does seem pretty sensible to have this syntax on That being said, I'm going to close this particular issue, since we've identified the issue and the answer is "Not supported", but I encourage you to open an issue relating more specifically to heredocs not being supported with the |
#2170 🎉 never got round to doing it, mostly due to lack of demand 😢 |
Description
when using HERE-DOC syntax for
RUN
CMD
in a dockerfile, while attemting to execute theenv
linux command, it gets interpreted asENV
for the dockerfile, and fails to build.Reproduce
create a dockerfile with HERE-DOC syntax for
one of its directives that support itCMD
make one of the lines in the here-doc "env" or "run" or something that is also a dockerfile directive
attempt to build
Expected behavior
docker should interpret the HERE-DOC correctly
docker version
Client: Docker Engine - Community Version: 25.0.4 API version: 1.44 Go version: go1.21.8 Git commit: 1a576c5 Built: Wed Mar 6 16:32:14 2024 OS/Arch: linux/amd64 Context: default Server: Docker Engine - Community Engine: Version: 25.0.4 API version: 1.44 (minimum version 1.24) Go version: go1.21.8 Git commit: 061aa95 Built: Wed Mar 6 16:32:14 2024 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.6.28 GitCommit: ae07eda36dd25f8a1b98dfbf587313b99c0190bb runc: Version: 1.1.12 GitCommit: v1.1.12-0-g51d5e94 docker-init: Version: 0.19.0 GitCommit: de40ad0
docker info
Additional Info
No response
The text was updated successfully, but these errors were encountered: