docker --output
With a one-liner (kinda) you can use docker as a build tool for binaries. I write “kinda” since you do need to adapt the Dockerfile for it. Can be neat if you don’t want to install a heavy toolchain, but still want to compile something to try out on your machine.
Here is a Dockerfile I’ve personally used to compile the OpenTelemetry collector using the OpenTelemetry collector builder. Requires BuildKit to work.
FROM otel/opentelemetry-collector-builder:0.142.0 AS builder
COPY builder-config.yaml builder-config.yaml
USER root
RUN apk add --no-cache git
USER ocb
RUN /usr/local/bin/ocb --config=builder-config.yaml
FROM scratch
COPY --from=builder /home/ocb/otelcol-dev /
Building the image with docker build -t otelcol -f Dockerfile --output=out . will result in the contents of /home/ocb/otelcol-dev being output to
a local folder ./out. We are using the scratch image as the final image so that we don’t end up with files that ship with the otel/opentelemetry-collector-builder builder image.
Official Docker documentation explaining --output.