Ankur Loriya
Ankur Loriya

Reputation: 3534

Docker - Docker Compose stop company level services not base services

I have base services like redis and mongodb which will share will multiple container of same image.

Once client requested new company we will create a new docker-compose file for the requested company with new port and configure apache to point new web port.

For start company-1 service with base services

docker-compose -f docker-compose.base.yml -f docker-compose-company-1.yml up -d

Same way for company-2

docker-compose -f docker-compose.base.yml -f docker-compose-company-2.yml up -d

This will create instance for base service and copmany services along with passed configuration for company.

While down the company-1 services

docker-compose -f docker-compose.base.yml -f docker-compose-company-1.yml down

This will down base services too but base services required by company-2

If we pass follwong command

docker-compose -f docker-compose-company-1.yml down

Throw error ERROR: Service 'company-1' has a link to service 'mongodb-service' which is undefined.

Can docker-compose solve our problem?

How can down specific copmany service not base services using docker compose down

More information about docker-componse files

docker-compose.base.yml services

docker-compose-company-1.yml services

Upvotes: 0

Views: 134

Answers (1)

sanu nt
sanu nt

Reputation: 64

You can use the extends: option in docker-compose to tackle this

docker-compose-base.yml

services:
    base:
    image:
    container_name:
    ports:

docker-compose-company.yml

services:
   custom:
    image:
    container_name:
    ports:

Create a new compose file with the services of both the base and company using

extends option of docker-compose

docker-compose-base-company.yml

services:
    base:
    extends:
    file: docker-compose-base.yml
    service: base

   custom:
    image:
    container_name:
    ports:

You can use docker-compose-base-company.yml to run the services of both base and company

docker-compose -f docker-compose-base-company.yml up .

and use docker-compose-company.yml to shutdown the company services alone

docker-compose -f docker-compose-company.yml down

Upvotes: 1

Related Questions