The suggested file structure for docker container is something like
root ├── app/ | ├── ... | └── Dockerfile | ├── db/ | ├── ... | └── Dockerfile ... └── docker-compose.yaml
So where do you put configuration files? If there is any overlap, and the app and the db need access to the same configuration, you immediately run into build context problems, since
COPY in Dockerfiles is restricted to the build context, which would be the
db/... sub-directories by default. And also should be those sub-directories to avoid sending tons of superfluous files to the docker daemon.
My current idea is to do something like this:
root ├── app/ | ├── ... | ├── Dockerfile-app.dockerignore | └── Dockerfile-app | ├── db/ | ├── ... | ├── Dockerfile-db.dockerignore | └── Dockerfile-db ... ├── config/ | ├── common | ├── app | ├── db | ├── ... └── docker-compose.yaml
Then I set the build context to root for every dockerfile, with the
Dockerfile-app.dockerignore looking like this:
* !app/* !config/common/* !config/app/* ...
this approach is heavily reliant on the relatively new Dockerfile.dockerignore feature which is referenced as largely "undocumented" in this issue: Add support for specifying .dockerignore file with -i/--ignore and not universally supported (e.g. tilt), which makes me quite uneasy about it.
At the same time a failure to recognize the dockerignore files only causes a slowdown and does not stop this method from working. So in that sense it is relatively stable. And the grouping as a config folder likely enables it to become a submodule and be version controlled separately which seems neat.
Or using the 'default/override' pattern there could be a
config folder, where the
config_default is tracked and the
config folder is put into
.gitignore. If you then init a git repository in the config folder you can probably use the two repositories independently, avoiding the infamous submodule complexity of git which I have not looked at yet.
Any different approaches, suggestions, comments?