Search code examples
dockerproduction-environmentdocker-compose

Symlinked Dockerfile for environments


I'm trying to find an elegant way to split/maintain my docker configurations for my environments.

Here is my current directory tree:

docker-compose.yml
docker-production.yml
dev/
    web/
        Dockerfile
        nginx.conf
        ...
    app/
        Dockerfile
    db/
        Dockerfile
prod/
    web/
        Dockerfile
    app/
        Dockerfile
    db/
        Dockerfile

As you can see, my services config are each contained into a subdirectory of each environment.

My docker-compose.yml is based on dev/ and docker-production.yml extends it and loads prod/

For an easier maintainability, I'm trying to use symlinks on the prod resources pointing to inherited files from dev depending on whether I'll need to change them or not. This would allow me to symlink an entire service directory or only certain files on it.

prod/
    web/
        Dockerfile -> ../../dev/web/Dockerfile
        nginx.conf
    app/ -> ../dev/app
    db/ -> ../dev/db

All seems to work fine but for the symlinked Dockerfiles:

Building web
ERROR: Cannot locate specified Dockerfile: Dockerfile

2 questions:

  • Does my technique seem ok to you or do you see any caveat/improvement ?
  • How can I make docker accept symlinked Dockerfiles ?

Solution

  • As I mentioned in the comments, using boot2docker means symlink are not supported.

    Seeing Cannot locate specified Dockerfile: Dockerfile is expected, especially if the symlink was created on the host (MacOs) and mounted by boot2docker (which won't interpret that symlink well)