2

Because of using multiple micro-services, with each micro-service having their own database dependencies (some overlap). I have a custom bash file that allows the developer to choose which microservices they want to run locally (for testing), it essentially builds a command:

EDIT: thanks to answer pointing out, you do need -f before every compose .yml file, I do use this, I just didn't originally type it out here.

docker-compose -f \
-f <docker-compose.ms1.yml> -f <docker-compose.ms2.yml> \
-f <docker-compose.dba> -f <docker-compose.dbb> \
up ms1-container ms2-container \
dba-container dbb container

Now this works fine, but traditionally (using a single .yml file and just running docker-compose up), if I wanted to see output logs, I would do docker-compose logs -f, or if I wanted to restart a particular service in the compose file, I would:

docker-compose stop <service_name>
docker-compose rm <service_name>
docker-compose create <service_name>
docker-compose start <service_name>

But now with it all started dynamically, how can I restart a particular docker-compose service, and also how can I tap back into the logs with logs -f?

1
  • docker logs -f <Container_name> schould do the trick Commented Jul 9, 2019 at 7:23

1 Answer 1

2

First I think your docker-compose command not valid, it should be:

docker-compose -f docker-compose_1.yaml -f docker-compose_2.yaml up -d

Then, everything is same with the one you just use one docker-compose.yaml:

E.g.

docker-compose_1.yaml:

version: '3'
services:
  frontend:
    image: alpine
    command: "tail -f /dev/null"

docker-compose_2.yaml:

version: '3'
services:
  backend:
    image: alpine
    command: "tail -f /dev/null"

You can still use docker-compose -f docker-compose_1.yaml -f docker-compose_2.yaml stop frontend to stop one service:

shubuntu1@shubuntu1:~/77$ docker-compose -f docker-compose_1.yaml -f docker-compose_2.yaml ps
    Name             Command         State     Ports
----------------------------------------------------
77_backend_1    tail -f /dev/null   Up
77_frontend_1   tail -f /dev/null   Exit 137

For logs, docker-compose -f docker-compose_1.yaml -f docker-compose_2.yaml logs for all service, while docker-compose -f docker-compose_1.yaml -f docker-compose_2.yaml logs backend for one service.

Reference to official guide:

You can supply multiple -f configuration files. When you supply multiple files, Compose combines them into a single configuration. Compose builds the configuration in the order you supply the files. Subsequent files override and add to their predecessors.

Sign up to request clarification or add additional context in comments.

1 Comment

Wow, didn't think of doing that, I am running a lot of containers right now that I can't close down to check. When I am free later, I will double check it works fine and accept you answer, thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.