Martin2904
Martin2904

Reputation: 333

Best practice - having multiple docker-compose files in a repo

I'am currently working on a fullstack web project that consists of the following components:

Every component should be deployable through docker. For that I have a Dockerfile for each of them. I also defined a docker-compose in the repository root to deploy all of them together.

# current repo structure
|frontend/
 |src/
 |docker/
  -Dockerfile
  -docker-compose.yml
|backend/
 |src/
 |docker/
  -Dockerfile
  -docker-compose.yml
|database/
 |src/
 |docker/
  -Dockerfile
  -docker-compose.yml
-docker-compose.yml

Do you think this is good practice? I am unsure because I think this my current structure is kind of confusing. How do you handle it in similar projects?

Upvotes: 3

Views: 1644

Answers (2)

breakthewall
breakthewall

Reputation: 183

docker-compose is designed to orchestrate multiple components of a project in one single place: docker-compose file.

In your case, and as m303945 said, you don't need multiple docker-compose files. Indeed, your main docker-compose.yml should call the Dockerfile of each of your component. This file could contain something like this:

services:

  frontend:
    build:
      context: frontend
      dockerfile: docker/Dockerfile

  backend:
    build:
      context: backend
      dockerfile: docker/Dockerfile

  database:
    build:
      context: database
      dockerfile: docker/Dockerfile

Upvotes: 3

Tarum
Tarum

Reputation: 993

you dont need multiple docker-compose files. if you want to run specific app together, for example only database and backend just run this command.

docker-compose -f docker-compose-file.yml up -d database backend 

which database and backend is service name in the docker-compose file.

Upvotes: 2

Related Questions