dockerdocker-composedocker-desktop

Docker Desktop grouping of containers run by a Docker Compose project


When running a Docker Compose project, its set of containers is displayed as a group in Docker Desktop:

Docker Desktop

What is the name of this grouping? (group, project...)
Neither docker ps nor docker container inspect display it.

Can we group containers in the same way outside Docker Compose?


Solution

  • Compose uses Docker labels to identify which containers go with which project. In the Go implementation of Compose ("Compose version 2"), these are in the github.com/docker/compose/v2/pkg/api Go package, in labels.go in the source tree. More specifically resources associated with a specific Compose project have a label com.docker.compose.project where the value is the Compose project name.

    As you note, "Compose project" is not a native part of core Docker. It doesn't show up in the Docker CLI at all, nor is it in the HTTP-over-Unix-socket API nor any of the standard SDKs. The only place it normally appears is in the proprietary Docker Desktop application.

    Nothing stops you from pretending your containers are part of a Compose project and adding this label yourself, and nothing stops other tooling from looking for Compose's labels. But at the end of the day it's just a label on Docker objects that happens to tie them together, that Docker Desktop happens to present specially.