Question: How do you organize the Dockerfiles belonging to a project when you have one Dockerfile for the database, one for the application server, and so on? Do you create some sort of hierachy in the source?
A big enterprise project can't consist of only one Dockerfile?

Answer: 
Use [`docker-compose`](https://docs.docker.com/compose/) and multiple `Dockerfile` in separate directories
----------------------------------------------------------------------------------------------------------

> 
> **Don't rename your `Dockerfile`** to `Dockerfile.db` or `Dockerfile.web`, it may not be supported by your IDE and you will lose syntax highlighting.
> 
> 
> 

As [Kingsley Uchnor said](https://stackoverflow.com/a/47837061/1092815), you can have multiple `Dockerfile`, one per directory, which represent something you want to build.

I like to have a `docker` folder which holds each applications and their configuration. Here's an example project folder hierarchy for a web application that has a database.

```
docker-compose.yml
docker
├── web
│   └── Dockerfile
└── db
    └── Dockerfile

```

`docker-compose.yml` example:

```yaml
version: '3'
services:
  web:
    # will build ./docker/web/Dockerfile
    build: ./docker/web
    ports:
     - "5000:5000"
    volumes:
     - .:/code
  db:
    # will build ./docker/db/Dockerfile
    build: ./docker/db
    ports:
      - "3306:3306"
  redis:
    # will use docker hub's redis prebuilt image from here:
    # https://hub.docker.com/_/redis/
    image: "redis:alpine"

```

`docker-compose` command line usage example:

```bash
# The following command will create and start all containers in the background
# using docker-compose.yml from current directory
docker-compose up -d

# get help
docker-compose --help

```

In case you need files from parent folder(s) as part of the build context of your Dockerfile
--------------------------------------------------------------------------------------------

You can still use the above solution and place your `Dockerfile` in a directory such as `docker/web/Dockerfile`, all you need is to set the build `context` in your `docker-compose.yml` like this:

```yaml
version: '3'
services:
  web:
    build:
      context: .
      dockerfile: ./docker/web/Dockerfile
    ports:
     - "5000:5000"
    volumes:
     - .:/code

```

The files hierarchy would loke like this:

```
config-on-root.ini
docker-compose.yml
docker
└── web
    ├── Dockerfile
    └── some-other-config.ini

```

The `./docker/web/Dockerfile` will have access to desired files from the context like this:

```docker
FROM alpine:latest

COPY config-on-root.ini /
COPY docker/web/some-other-config.ini /

```

Also note that the build context will contain all the files of the specified directory. Make sure tou use a `.dockerignore` file to prevent loading undesired large files or directories to save time during build.

[Here are some quick commands from tldr docker-compose](https://github.com/tldr-pages/tldr/blob/master/pages/common/docker-compose.md). Make sure you refer to [official documentation](https://docs.docker.com/compose/) for more details.
When working on a project that requires the use of multiple dockerfiles, simply create each dockerfile in a separate directory. For instance,

app/
db/

Each of the above directories will contain their dockerfile. When an application is being built, docker will search all directories and build all dockerfiles.