Can I pass parameters to a RUN
instruction from the command line when doing docker build
?
My image is building my application using a build system, the purpose would be to be able to select different build target from the command line. Otherwise I would need a separate Dockerfile for each desired build target which is not really maintainable.
I feel like the caching system could be in the way of this feature, although it seems quite doable.
As an example, the instruction would look like:
RUN bazel build $BUILDOPTS //my/app:$TARGET
I've looked into passing args with --build-args
but didn't succeed with it.
CodePudding user response:
You should add ARG
to your Dockerfile.
ARG BUILDOPTS
ARG TARGET
RUN bazel build $BUILDOPTS //my/app:$TARGET
Read more: https://docs.docker.com/engine/reference/builder/#arg