Docker Community Forums

Share and learn in the Docker community.

Adding container to running docker-compose group programmatically

I am looking to do something which I am not even sure is feasible. I am newish to docker and blindly making my way through it atm.

I am on Windows using Docker for Desktop
I have a docker-compose group of containers that is up and running. These containers can be seen in the user interface under the same “group” node, which is named after the project under which the docker-compose file resides.

I am using the docker python sdk to dynamically create new containers based on an existing pre-built image. I would like those new containers to appears as part of the same “group”; Right now they are being listed separately, no matter what I try.

I thought this had to do with the common network they join, so I had the runtime-created containers join the same network, but it does not change the fact that they are still listed outside of my “compose” environment in the UI (my understanding is that now they will be able to talk to each other using their docker service name in place of IPs)

Am I seeing too far into this? is what I want to achieve even possible? I’ve tried network, groups, etc…

I usually end up having multiple yml files.

Then you can add several -f flags to docker-compose command to indicate which services to run.

For instance, having:

docker-compose.yml: containing basic services
docker-compose-additional-services.yml: containing additional/optional services.
You can execute to start:

docker-compose -f docker-compose.yml -f docker-compose-additional-services.yml up
And it will start all services.

Note, that all services are merged as if they were in a single file, so you can reference (depends_on, link) services from one file to the other.