Today I Learned (April 11, 2024)

It’s possible to write multiline RUN commands using heredoc syntax

In essence, this well known pattern (joining command invocations together over multiple lines with && \)

FROM ubuntu:22.04

RUN apt-get update && \
  apt-get upgrade -y && \
  apt-get install -y curl

may be replaced with this

FROM ubuntu:22.04

RUN <<EOF
set -e
apt-get update
apt-get upgrade -y
apt-get install -y curl
EOF

:bulb: The heredoc syntax is enabled by default when building with BuildKit (standard for DockerDesktop as well as DockerEngine since v23.0). It doesn’t apply to older versions or when not building with BuildKit.

:warning: This feature is not supported in Kaniko.

:link: https://www.docker.com/blog/introduction-to-heredocs-in-dockerfiles/