Heredocs


Heredocs

$ cat <<EOF
line1
line2
EOF
line1
line2

Supported in Dockerfile with experimental syntax >= 1.3-labs

Fist line of Dockerfile must be:

# syntax=docker/dockerfile:1.3-labs

Demo: Heredocs 020_advanced/180_heredocs

Use RUN like a script block

No more && and \

RUN <<EOF
ps faux
EOF

Test RUN with script block:

docker build . --file Dockerfile.run

Demo: Heredocs 020_advanced/180_heredocs

Use a custom interpreter for the script block

RUN bash -xe <<EOF
echo foo
EOF

Test RUN with interpreter:

docker build . --file Dockerfile.interpreter

Demo: Heredocs 020_advanced/180_heredocs

Provide shebang to set interpreter

RUN <<EOF
#!/bin/bash
ps faux
EOF

Test RUN with script:

docker build . --file Dockerfile.script

Demo: Heredocs 020_advanced/180_heredocs

Provide inline file

COPY --chmod=0755 <<"EOF" /entrypoint.sh
#!/bin/bash
exec "$@"
EOF

Test COPY with inline file:

docker build . --file Dockerfile.copy

Demo: Heredocs 020_advanced/180_heredocs

Create multiple files in a single COPY

COPY <<no-recommends <<no-suggests /etc/apt/apt.conf.d/
APT::Install-Recommends "false";
no-recommends
APT::Install-Suggests "false";
no-suggests

Test COPY with multiple files:

docker build . --file Dockerfile.copy-multiple