Docker Community Forums

Share and learn in the Docker community.

COPY only if file exist

docker

(Shurikag) #1

Hi All,

Is there a way to execute COPY only if the file exists on the host?
Maybe there is a way to do that check from a shell script that is executed in Dockerfile…

Thanks,
Alex.


(Ranjandas) #2

Hi,

COPY instruction in Dockerfile expects a file to exist in the source location mentioned. If the source file is not there the build will fail. Dockerfie doesn’t have the feature to conditionally execute instructions.

Regards


(Dylan Smith) #3

You can use wildcards to optionally copy. For example, to COPY a yarn.lock file that may or may not exist, do:

COPY package.json yarn.* /opt/app/