Dockerfile and if statement

Viewed 139

I have a Dockerfile, I want to copy file if the comparaison is correct for the Dockerfile, but after docker build and docker run, the file is not present on docker, it lack of something ?

ARG A_ARG
RUN if [ "$A_ARG" = "toto" ]; then cp files/opt/toto.sh /opt; chmod +x /opt/toto.sh; fi


docker build --build-arg A_ARG=toto .
docker run id_contenair
1 Answers

Files are only accessible to the image using a COPY directive, akin to your RUN.

Using cp in a RUN command can be used to move files, but only if they are already present.

I would recommend pulling all the files you might need in, then removing the unnecessary folders based on your argument.

Once that logic is finalized, use a multi stage layer to copy your final complete set of files to a clean image

Related