Home > Back-end >  Copy all files of sub and nested sub directories
Copy all files of sub and nested sub directories

Time:11-13

This is my project file structure:

java-project/
├── docker.compose.yml
├── pom.xml
└── services/
    ├── a/
    │   ├── Dockerfile
    │   ├── pom.xml
    │   ├── src/
    │   │   ├── pom.xml
    │   │   ├── xxx
    │   │   └── xxx
    │   └── target/
    │       ├── pom.xml
    │       └── xxxx
    └── b/
        ├── Dockerfile
        ├── pom.xml
        ├── src/
        │   ├── pom.xml
        │   ├── xxx
        │   └── xxx
        └── target/
            ├── pom.xml
            └── xxxx

I want to copy all the contents of the services folder of the project (including all the sub folders inside the services). Basically, I want to replicate the current project structure with every file and folder in the docker image as well for the mvn build to execute successfully. I am doing the following in Dockerfile, but I don't see all the contents COPY services/**/pom.xml ./services/

What am I doing wrong here? TIA

CodePudding user response:

Let's look at your COPY instruction:

#    <src>               <dest>
COPY services/**/pom.xml ./services/

Under the hood, Docker reads the <src> using Go's filepath.Match method. This means that the instruction doesn't use the globstar (**) the way glob patterns do. However, your question suggests you want to copy everything inside services — not only pom.xml files.

You can copy everything inside your local services directory using:

COPY services ./services/

If you want to exclude certain subdirectories or files, you can specify this using a .dockerignore.

  • Related