Skip to content

Instantly share code, notes, and snippets.

@qmacro
Created January 18, 2024 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qmacro/b0519de87c385d164a855b0d28aba641 to your computer and use it in GitHub Desktop.
Save qmacro/b0519de87c385d164a855b0d28aba641 to your computer and use it in GitHub Desktop.
Dockerfile heredoc test
# syntax=docker/dockerfile:1
# Definition of 'false': 'does nothing, unsuccessfully' (i.e. emits an error exit code)
FROM alpine as old-way
RUN \
echo hello && \
false && \
echo goodbye
FROM alpine as new-way
RUN <<TESTINGIMPLICITDOUBLEAMPERSAND
echo hello
false
echo goodbye
TESTINGIMPLICITDOUBLEAMPERSAND
@qmacro
Copy link
Author

qmacro commented Jan 18, 2024

Building via the old way, i.e.

docker build --no-cache --target old-way --progress plain -t test .

We see:

#0 building with "default" instance using docker driver

#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 95B 0.1s
#1 transferring dockerfile: 334B 0.1s done
#1 DONE 0.1s

#2 [internal] load .dockerignore
#2 transferring context: 2B 0.1s done
#2 DONE 0.1s

#3 resolve image config for docker.io/docker/dockerfile:1
#3 DONE 0.7s

#4 docker-image://docker.io/docker/dockerfile:1@sha256:ac85f380a63b13dfcefa89046420e1781752bab202122f8f50032edf31be0021
#4 CACHED

#5 [internal] load metadata for docker.io/library/alpine:latest
#5 DONE 0.0s

#6 [old-way 1/2] FROM docker.io/library/alpine:latest
#6 CACHED

#7 [old-way 2/2] RUN    echo hello &&    false &&    echo goodbye
#7 0.077 hello
#7 ERROR: process "/bin/sh -c echo hello &&    false &&    echo goodbye" did not complete successfully: exit code: 1
------
 > [old-way 2/2] RUN    echo hello &&    false &&    echo goodbye:
0.077 hello
------
Dockerfile:4
--------------------
   3 |     FROM alpine as old-way
   4 | >>> RUN \
   5 | >>>    echo hello && \
   6 | >>>    false && \
   7 | >>>    echo goodbye
   8 |
--------------------
ERROR: failed to solve: process "/bin/sh -c echo hello &&    false &&    echo goodbye" did not complete successfully: exit code: 1

Building via the new way, i.e.

docker build --no-cache --target new-way --progress plain -t test .

We see:

#0 building with "default" instance using docker driver

#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 95B 0.1s
#1 transferring dockerfile: 334B 0.1s done
#1 DONE 0.1s

#2 [internal] load .dockerignore
#2 transferring context: 2B 0.1s done
#2 DONE 0.1s

#3 resolve image config for docker.io/docker/dockerfile:1
#3 DONE 1.4s

#4 docker-image://docker.io/docker/dockerfile:1@sha256:ac85f380a63b13dfcefa89046420e1781752bab202122f8f50032edf31be0021
#4 CACHED

#5 [internal] load metadata for docker.io/library/alpine:latest
#5 DONE 0.0s

#6 [new-way 1/2] FROM docker.io/library/alpine:latest
#6 DONE 0.0s

#6 [new-way 1/2] FROM docker.io/library/alpine:latest
#6 CACHED

#7 [new-way 2/2] RUN <<TESTINGIMPLICITDOUBLEAMPERSAND (echo hello...)
#7 0.071 hello
#7 0.071 goodbye
#7 DONE 0.1s

#8 exporting to image
#8 exporting layers done
#8 writing image sha256:9c1fb9833b686f4515a49cbf0dd713f1bab6f0655d901cae86682dc33150656b done
#8 naming to docker.io/library/test done
#8 DONE 0.0s

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