I have the following setup.
Folder structure
solution-root
├── docker-compose.yml
├── project1
│ ├── Dockerfile
│ ├── sub1
│ │ ├── ...loads of stuff...
│ ├── sub2
│ │ ├── ...more stuff...
├── project2
│ ├── Dockerfile
│ ├── sub1
│ │ ├── ...more stuff...
│ ├── sub2
│ │ ├── ...even more stuff...
├── project-db
│ ├── Dockerfile
docker-compose.yml
version: '3'
services:
project1:
build:
context: ./project1
dockerfile: Dockerfile
...
project2:
build:
context: ./project2
dockerfile: Dockerfile
...
project-db:
build:
context: ./project-db
dockerfile: Dockerfile
...
...
project-db/Dockerfile
FROM mysql:5.7
COPY ../project1/app/seeders /seeders/
COPY ../project2/app/seeders /seeders/
Obviously, I want to copy files from another sibling folder because this project-db needs them.
So, when I run docker-compose build I am presented with this error:
Service 'project-db' failed to build: COPY failed: Forbidden path outside the build context: ../project1/app/seeders
Ok, I get it, context does not allow me to level up. Let's move context to root then and then run project/Dockerfile from there.
docker-compose.yml
project-db:
build:
context: .
dockerfile: ./project-db/Dockerfile
...
Now we can copy files that we need.
project-db/Dockerfile
COPY project1/app/seeders /seeders/
COPY project2/app/seeders /seeders/
And now all is well(ish) with docker-compose build.
BUT there is a problem - building project-db lasts quite some time. And that means every time it's being run. I guess that it's due to the fact that now the context of the project-db is the entire folder structure.
So, I tried with .dockerignore to filter out unneeded folders:
.dockerignore
project3
project3/**
project4
project4/**
project5
project5/**
...
But nothing removes that lag.
I can't get this to work properly. Also - I can't fiddle with the internal structures of the existing projects.
What is wrong here?