Currently all CLI (docker or docker-compose) commands have the possibility to overwrite via the switch -l
or --label
the labels of the services/containers to run or volumes/networks to create. The docker-compose up
does not have such an option.
See for example Add labels in docker-compose run #4937 where such an option was added for docker-compose run
If we start a docker-compose stack on a swarm multiple times, then different labels can be used to identify the started services/containers.
Adding the labels at command line level would free us from knowing any insights of what we started and free us from changing the compose file.
We can for example run several docker-compose stacks multiple times in a CI test scenario. On an error situation we can simply enforce by filtering by labels that what ever had been tested (container, services, volumes, networks, etc.) is removed from the swarm.
docker-compose version 1.22.0, build f46880fe
docker-py version: 3.4.1
CPython version: 3.6.6
OpenSSL version: OpenSSL 1.0.2o 27 Mar 2018
I would be very happy if I could take care of it, but I need information from the maintainer, if anyone is already working on it. And if you want, give me some hints.
@jewertow It may be helpful to look at this MR: https://github.com/docker/compose/pull/5397 which implemented the label for docker-compose run
.
In the meantime, and as a workaround, you can pass a label using an environment variable and variable substitution in the docker-compose file.
Well, yeah, fine. I didn't think to do it that way. It's a workaround. Although the command-line version would be nice, as it doesn't force us to write our composed files for specific use cases.
Is there really no way to assign a label using docker-compose? Came here looking how to do it since I have some filters on labels that I would like to assign to a docker-compose stack. Would really like this functionality.
Just hit this issue in 2020, could this year get any worse? My use case is I want to be able to automatically clean up resources created by a given docker-compose. To achieve this I want to tag all resources (containers/volumes/networks) with a given label so I can track and remove them later, something like docker-compose -l custom=true up
would be great
Most helpful comment
Is there really no way to assign a label using docker-compose? Came here looking how to do it since I have some filters on labels that I would like to assign to a docker-compose stack. Would really like this functionality.