docker COPY with file globbing
For any non-standard build operation, I prefer wrapping the docker build
command in a script (named 'build
').
Here I would
- create a subfolder
tmp
(just beside theDockerfile
, in order to keep it in thedocker build
context) - make the shell
cp
with globing:cp ./src/**/project.json tmp
- call
docker build
, with aDockerfile
includingCOPY tmp/ /app/
- deleting
tmp
.
That way, I pre-configure what I need from host, before building the image from the host context.
Little late, but with multistage building, you can get this behavior. Here I do it for a large maven build
FROM maven:3.6-slim as stagingWORKDIR /src/COPY . .RUN mkdir /poms/ \ && find ./ -type d -exec mkdir -p '/poms/{}' \; \ && find ./ -name pom.xml -exec cp -r '{}' '/poms/{}' \;FROM maven:3.6-slim as builderWORKDIR /src/COPY --from=staging /poms/* ./RUN mvn dependency:go-offline
A bit of a hack, but given that it's a multistage, the first stage just get's thrown away and the copy is a cheap operation