Home > Blockchain >  Can I up or stop resources referring to a specific "docker-compose.yml" individually?
Can I up or stop resources referring to a specific "docker-compose.yml" individually?

Time:12-28

I'm new to the world of containers and specially when it comes to Docker Compose. I'm confused about some concepts and I can't find information about them.

Basically I want to know if I can handle settings in different "docker-compose.yml" files in a isolated manner. I explain better... I would like to know if I can up or stop resources referring to a specific "docker-compose.yml" individually.


PLUS:

To better explain my doubt I'll show you some conjectures about what I'm trying to explain.

It seems to me that it is possible to have multiple configurations for Docker Compose using different ".yml" files like the example below...

EXAMPLE

docker-compose -f docker-compose.a.yml -f docker-compose.b.yml up -d

... and that I can also handle each of these settings individually, such as stopping all the resources referring to a specific docker-compose.yml...

EXAMPLE

docker-compose -f docker-compose.b.yml stop

[Ref(s).: https://gabrieltanner.org/blog/docker-compose#using-multiple-docker-compose-files , https://stackoverflow.com/q/29835905/3223785 , https://stackoverflow.com/questions/42287426/docker-multiple-environments , https://runnable.com/docker/advanced-docker-compose-configuration ]

CodePudding user response:

Yes, it is possible. I'm not exactly sure what you are trying to do, but to be able to manage the services using -f option the way that you described, there shouldn't be a service with the same name on multiple files. For example, if you have a service called db in docker-compose.a.yml and one other db service in docker-compose.b.yml. The following command will only built one container for db service:

docker-compose -f docker-compose.a.yml -f docker-compose.b.yml up -d

Take a look at -p option. It will make a project with the services isolated inside it. Then you can manage them using following commands with the same docker-compose.yml file:

docker-compose -p foo up -d
docker-compose -p foo stop [service_name]

CodePudding user response:

yes you can.

It is just a matter of preference but i usually create a folder for every project i have, each of them have a unique docker-compose.yml file in it with all its dependencies (frontend / database /redis)

Then to start a specific project i just go inside its folder and run docker-compose up. it then only starts this project without touching others.

you can also type this if you only want to start redis.

docker-compose up redis
  • Related