You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Dockerfile containing RUN with heredoc is accepted by docker build but not docker buildx build, where you get "error: failed to solve: rpc error: code = Unknown desc = unterminated heredoc"
#2891
Closed
oliverlockwood opened this issue
May 31, 2022
· 5 comments
My (obviously simplified for demonstration purposes) Dockerfile:
FROM debian:buster
RUN echo <<EOF \
hello \
mr \
potato \
EOF > /tmp/output && \
echo 'done'
(although, based on comments in #2439, I have also tried line 3 as RUN echo <<-"EOF" \ without any difference in behaviour). #2170 seems to suggest that heredoc in RUN commands is supported, though I couldn't see an example where the Herero
Running a normal docker build:
mycomputer$ docker build --no-cache -f Dockerfile --pull -t ogl-test .
Sending build context to Docker daemon 42.82MB
Step 1/2 : FROM debian:buster
buster: Pulling from library/debian
Digest: sha256:e5b41ae2b4cf0d04b80cd2f89724e9cfc09e334ac64f188b9808929c748af526
Status: Image is up to date for debian:buster
---> 354ff99d6bff
Step 2/2 : RUN echo <<-"EOF" hello mr potato EOF > /tmp/output && echo 'done'
---> Running in 615df9c4f39e
done
Removing intermediate container 615df9c4f39e
---> 1107a46f07b7
Successfully built 1107a46f07b7
Successfully tagged ogl-test:latest
mycomputer$ docker run -it ogl-test
root@9adca399ee6f:/# cat /tmp/output
hello mr potato EOF
root@9adca399ee6f:/# exit
exit
Just to sanity check - are you doing both builds with buildkit? You should be able to confirm by comparing the results of DOCKER_BUILDKIT=1 docker build . and DOCKER_BUILDKIT=0 docker build .
Heredocs are only supported in buildkit, and probably won't be backported to the legacy builder.
Remember, that heredoc terminators need to be terminated without the indent. Your example would probably need to look more like (using cat instead of echo, to actually read the heredoc):
FROM debian:buster
RUN cat <<EOF > /tmp/output && echo 'done'
hello
mr
potato
EOF
@jedevc thanks for getting in touch. With your suggested Dockerfile, regardless of whether I use DOCKER_BUILDKIT=0 or DOCKER_BUILDKIT=1, it errors like this:
failed to solve with frontend dockerfile.v0: failed to create LLB definition: dockerfile parse error line 4: unknown instruction: HELLO
If I change this to include newline escapes, i.e.:
FROM debian:buster
RUN cat <<EOF > /tmp/output && echo 'done' \
hello \
mr \
potato \
EOF
then it builds, but in both cases the /tmp/output file is empty.
If I return to my original Dockerfile, then docker build behaves identically regardless of the setting of DOCKER_BUILDKIT.
I still cannot find an incantation which produces content in an output file (thereby simulating the actual commands I want to run) and works in docker buildx build, as per the original issue description.
Perhaps you can try it at your end? The idea behind my producing a simplified repro scenario was that it would be easy for you to reproduce the issue yourself 😃
Hey! So glanced through your version information again - it doesn't look like you have a version that supports heredocs. It was released about a year ago, and heredocs weren't in the stable channel then.
Take a look through the examples presented in the documentation: you'll need to include the #syntax=docker/dockerfile:1.4 or some other version that includes heredocs support.
I can't reproduce the scenario you're describing on an up to date docker installation, have a try with the syntax directive 🎉
My (obviously simplified for demonstration purposes)
Dockerfile
:(although, based on comments in #2439, I have also tried line 3 as
RUN echo <<-"EOF" \
without any difference in behaviour).#2170 seems to suggest that heredoc in RUN commands is supported, though I couldn't see an example where the Herero
Running a normal
docker build
:Running
docker buildx build
:Version information:
The text was updated successfully, but these errors were encountered: