-
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
Docker Here-Documents line endings #3329
Comments
Thanks for the bug report 🎉 Sorry it's taken so long to get round to, the v0.11 release has made things a bit busy 👍 This is tricky 😬 One of the things discussed when designing the original heredocs syntax was that it's important to preserve the contents of the heredoc as much as possible. For the most part, the heredocs really aren't processed by buildkit - except to detect the end of them, and pass them to the shell, in your case, Now, we could potentially strip away the CLRF newlines, and replace them with LF newlines ('\n'). However, in doing that we'd be making assumptions about how a given shell works. We've tried to avoid this kind of assumption as much as possible - to do this properly, we'd actually need to implement full-on quote parsing, something we really want to avoid doing (mostly because writing sh-compliant quote parsing is a misery, and very easy to screw up). For example: RUN <<EOT
echo "foo
bar"
EOT If we perform CLRF replacement here, it's probably not alright to remove it in the middle of the echo - but to know that, we'd need to implement the quote parsing. I think we probably want to fix this with docs/tooling changes, as opposed to manipulating the contents of the heredoc. I think it's probably something we can add in the docs somewhere, at the very least clarifying how heredoc content is captured and passed to the shell. I'm not sure if we would want a warning: it could be valid for a shell to accept CRLF line endings - for example, powershell both on windows and linux allows it (I think?). Maybe long-term this is information to be captured by a linter - there has been discussion as to whether there should be an official dockerfile linter, and maybe one of the rules should be to detect if CRLF endings are being used. TL;DR: I think a docs change here is reasonable, anything else is probably out-of-scope for now. |
As a workaround if you want to continue to use CRLF endings, you could use something like the following: RUN cat <<EOT | tr -d '\r' | sh
...
EOT However, I'd probably lean towards a solution that removes windows-line endings from the Dockerfile in the first place. |
moving tracking for this issue to #4282 |
Problem description
Scripts either passed to
RUN
or created byCOPY
do not work if the image is built on Windows.Steps to recreate
docker build -t here-file-test:latest .
Expected outcome
The image is built.
Actual outcome:
Reason for build failure
If a Dockerfile is created - or checked out from Git - on Windows, chances are that it has CLRF line endings, as those are the Windows default. The current implementation of Here-Documents uses whatever line endings Dockerfile has when creating those files. This breaks the build as Linux shells cannot correctly run scripts with CLRF line endings for some reason - although there's a patch for Bash that fixes that.
Possible solution
I don't know what the proper solution for this issue should be or is possible to implement. Still, I'd expect BuildKit, instead of using whatever line endings are in the Dockerfile, would use the default line endings for the architecture reported by Docker Engine as even on Windows
docker version
correctly reports its architecture as linux/amd64.At the very least it should be mentioned in the documentation as a possible problem.
The text was updated successfully, but these errors were encountered: