May I ask where conditional operations in COPY instructions are addressed in the docs? I can not find anything like that in the COPY section of the Dockerfile referece…
The only instruction I am aware of that supports conditional operations is the RUN instruction.
Now this part is at least valid syntax. Note: since RUN executes in sh/bsah the condition operation is brought from sh/bash to the table, not from the RUN instruction itself!
This part is still invalid. You can not wrap other instructions in instructions.
What about this: RUN if [ "$BASE_IMAGE" = "idit-external" ] ; COPY --from=BUILD $TMP_LOCATION/*.xml $DEPLOYMENT_LOCATION ; fi
If this work, i can make some repetition.
Or else please suggest any other wrokaround for this.
Likewise, you could probably use Bash cp (as in RUN cp ...) to copy things around. But I doubt you’d know where the result of the temporary build image is stored on disk (to replace the part --from=BUILD with a Bash equivalent).
I ended up copying my entire Dockerfile in a subdirectory, deleting two lines for copies I didn’t want in that case, and calling that file in my Makefile - ugly! Please support conditional COPY!
it deepends on what you are looking for. You could leverate buildkit syntax to “unlock” features, like Build Mounts and copy the files in a RUN instruction to the mount and copy them conditionaly back inside a shell if condition wrapped in a RUN instruction.
Or if it’s just about conditionaly using different paths, then its even simpler.
You can use conditional values for MY_SRC_PATH and DST_PATH to pass in values on each build. The conditional part has to happen outside the build: docker build --build-arg MY_SRC_PATH=${src} --build-arg MY_DST_PATH=${dst} ...
Then in you Dockerfile use the passed-in values as args in your COPY instruction:
Both solutions are probably not what you want. The ARG one can actualy be quite powerfull if used right. Though, there is no way to skip the COPY instruction conditionaly.