RUN

The Dockerfile instruction that runs a command during the build and saves the result as a new layer.

In more detail

Use it to install packages or compile code: RUN apk add --no-cache curl. Each RUN is one layer, so chain related commands with && and clean caches in the same RUN, otherwise deleted files stay in the earlier layer. RUN --mount=type=secret gives a command a secret without storing it in the image.

Examples

RUN chmod +x app.sh
RUN apk add --no-cache curl
RUN CGO_ENABLED=0 go build -o /out/app .
RUN ./mvnw -B -ntp package -DskipTests

Related terms

Taught in

References

Certification courses