Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

166
Views
docker COPY with file globbing

Inside the dockerfile, I want to specify a copy operation for files which are defined by globbing and I want it to be copied with the path as well. So, something like this:

COPY ./src/**/project.json /app/**/

Considering I have the following structure:

./src/bar/project.json
./src/foo/project.json

The destination should look like this:

/app/bar/project.json
/app/foo/project.json

but apparently, this doesn't work and I really don't want to specify all of the COPY operations separately if I have a chance. Any idea how to do this?

Note that I cannot basically ignore other files through .dockerignore as suggested as I am going to copy the other files from the same folder after ruining a package install operation. So, the dockerfile is similar to this:

FROM microsoft/aspnet:1.0.0-rc1-update1

COPY ./src/**/project.json /app/**/
WORKDIR /app/ModernShopping.Auth
RUN ["dnu", "restore"]
ADD ./src /app

EXPOSE 44300
ENTRYPOINT ["dnx", "web"]
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

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 the Dockerfile, in order to keep it in the docker build context)
  • make the shell cp with globing: cp ./src/**/project.json tmp
  • call docker build, with a Dockerfile including COPY tmp/ /app/
  • deleting tmp.

That way, I pre-configure what I need from host, before building the image from the host context.

over 4 years ago · Santiago Trujillo Report

0

Workaround

Dockerfile:

COPY src/ /app/

.dockerignore:

**
!**/project.json
over 4 years ago · Santiago Trujillo Report

0

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 staging

WORKDIR /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 builder

WORKDIR /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

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!