Multiple docker compose stacks and docker contexts

I have made a context to a remotehost and can docker context to the remote host (docker-compose ls works). On that remote host I have two docker compose stacks running. One run from the command line (nginxproxymanager) and one is managed by portainer (sonarqube)

When I do a ls on the remote host I get to see this:

NAME STATUS CONFIG FILES
nginxproxymanager running(3) /opt/nginxproxymanager/docker-compose.yaml
sonarqube running(2) /Users/ihullu/Systemation/sonarqube/docker-compose.yaml

When I do ps on the remote host I see this.

NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
postgres-db postgres:14 “docker-entrypoint.s…” db2 36 minutes ago Up 23 minutes 5432/tcp
sonarqube-sonarqube-1 sonarqube:community “/opt/sonarqube/dock…” sonarqube 36 minutes ago Up 5 seconds 9000/tcp

These are the services of one of the two docker compose stacks namely nginxproxymanager. This stack runs from the command line. The second stack is managed by portainer.

When I try to remotely up and down one of the two docker compose stacks this only works for one stack (the one managed by protainer namelijk sonarqube). When I do a docker ps I only see the container of this stack.

So how do I switch between stacks remotely? Or is this not possible?

When I do a docker compose ps on the server host I see this

NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
nginxproxymanager-app-1 jc21/nginx-proxy-manager:latest “/init” app 18 hours ago Up 8 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp, 81/tcp
nginxproxymanager-db-1 jc21/mariadb-aria:latest “/scripts/run.sh” db 18 hours ago Up 8 minutes 3306/tcp
nginxproxymanager-portainer-1 portainer/portainer-ee:latest “/portainer -H unix:…” portainer 18 hours ago Up 8 minutes 8000/tcp, 9000/tcp, 9443/tcp

These are the services from the nginxproxymanager stack and not the portainer managed sonarqube stack.

Can anyone explain to me what I am doing wrong and how to do it right?


LOCAL:
Docker Engine - Community (local), Engine 25.0.3
Docker Compose version v2.24.6-desktop.1

SERVER
Server Engine Version: 25.0.3
Docker compose: Docker Compose version v2.24.7

A docker compose deployment is called project (e.g. docker compose up) a docker swarm deployment is called stack (e.g. docker stack deploy). I assume you are not referring to swarm stack deployments.

Portainer calls both stack, but this does not reflect the Docker terminology you will find in the official documentation.

Please test following things:

  • change into a folder in your terminal that does not include a compose file
    • execute: docker compose ls → it will show all project
    • execute: docker compose ps → it will throw an error that no compose file exists in the folder, unless you specify it using the argument -f path/to/the/compose/file/compose.yml or -f path/to/the/compose/file/docker-compose.yml
    • execute: docker ps -a → it will list all containers that exist on the remote engine.
    • execute: docker compose -f /opt/nginxproxymanager/docker-compose.yaml ps
    • execute: docker compose -f /Users/ihullu/Systemation/sonarqube/docker-compose.yaml ps

What you see is how the two sub commands are designed to work, regardless whether you use the default local or remote context. Your expectation, how you feel it should work just doesn’t align with how it actually works.

The question is confusing. In case something is unclear, it is always a good idea to take a look into the docs:

Thank you for clarifying the terminology. I was a little confused portainer calls everything stacks.

Now I understand you need to have the docker compose file locally. Then you switch context to the remote machine (I remain on the local machine). Startup the project (dc file). I see the image is loaded on the remote machine and the (minecraft) container is started on the remote machine.

The only thing is when I do a docker compose ps locally it shows me three containers instead of one.

$ docker compose ps
NAME                         IMAGE                   
postgres-db  (?)             postgres:14             
sonarqube-minecraft-1        itzg/minecraft-server   
sonarqube-sonarqube-1 (?)    sonarqube:community

This is a combination of the minescraft project I just started with a project I have running on the remote machine (managed by portainer). That somewhat surprised me, I only expected to see the minecraft container/service.

But I might be wrong.

That’s surprising, unless all those containers are in the same compose file. docker compose ps should only list containers managed by that project (which is the folder name, if no project-name is specified)