I've got a file containing a list of paths that I need to copy by Dockerfile's COPY
command on docker build
.
My use case is such: I've got a python requirements.txt
file, when inside I'm calling multiple other requirements files inside the project, with -r PATH
.
Now, I want to docker COPY
all the requirements files alone, run pip install, and then copy the rest of the project (for cache and such). So far i haven't managed to do so with docker COPY
command.
No need of help on fetching the paths from the file - I've managed that - just if it is possible to be done - how?
thanks!
Not possible in the sense that the
COPY
directive allows it out of the box, however if you know the extensions you can use a wildcard for the path such asCOPY folder*something*name somewhere/
.For simple
requirements.txt
fetching that could be:But if it gets a bit more complex (as in collecting only specific files, by some custom pattern etc), then, no. However for that case simply use templating either by a simple F-string,
format()
function or switch to Jinja, create aDockerfile.tmpl
(or whatever you'd want to name a temporary file), then collect the paths, insert into the templatedDockerfile
and once ready dump to a file and execute afterwards withdocker build
.Example: