Copy asset with location found via shell function
I have an asset which needs to be copied to the docker image, but whose location I do not know beforehand: I need to run a shell command to find it:
How can this be combined with the
COPY command in a Dockerfile? Usually I do:
COPY app.json /usr/src/app
But now I need to do:
COPY `where-is-my-asset` /usr/src/app
One Solution collect form web for “Copy asset with location found via shell function”
ARG will let you define a dynamic argument to the build but I don’t believe you can run a command in the
Dockerfile to populate the argument.
You could source it beforehand. With a Dockerfile like…
FROM busybox ARG assetfile COPY $assetfile /somehwere
docker build --build-arg assetfile="$(where-is-my-asset)" .
Which is not much different to just doing it in the shell.
cp "$(where-is-my-asset)" . docker build .