How to log a given instance of a scaled service with docker-compose?

Viewed 113

I have a docker-compose.yml file which contains, among others, an application service app.

When I start this service using the up --scale app=N option (with N>1) I can monitor what's happening in the service using docker-compose logs app but this list all the instances of the app service, namely, app_1, app_2, ..., app_N.

Let's say I'd like to only see the logs of the app_4. How could I achieve that?

The help doesn't help me much on that:

ubuntu-host-machine$ docker-compose logs --help
View output from containers.

Usage: logs [options] [--] [SERVICE...]

Options:
    --no-color          Produce monochrome output.
    -f, --follow        Follow log output.
    -t, --timestamps    Show timestamps.
    --tail="all"        Number of lines to show from the end of the logs
                        for each container.

I naturally tried docker-compose logs app_4 but without much success, as it says:

ERROR: No such service: app_4

The same error appears if I want, e.g. to stop the app_4 using docker-compose stop app_4 and will probably for other similar commands. So the question may also apply to these similar situations.

Versioning information:

ubuntu-host-machine$ docker-compose --version
docker-compose version 1.27.4, build 40524192

ubuntu-host-machine$ docker --version
Docker version 20.10.8, build 3967b7d

ubuntu-host-machine$ uname -mor
5.4.0-81-generic x86_64 GNU/Linux
0 Answers
Related