cli icon indicating copy to clipboard operation
cli copied to clipboard

Add Indicator in `docker ps` for Containers Created with docker-compose

Open kha84 opened this issue 1 year ago • 1 comments

Description

It would be incredibly helpful if docker ps could include a built-in indicator showing whether a container was created using docker-compose or docker run directly, without requiring additional commands or manual inspection.

Problem

Currently, there is no straightforward way to immediately tell from docker ps whether a container was created with docker-compose. Users have to:

  • Rely on naming conventions (which can be customized and aren’t always reliable).
  • Run docker inspect to check for the com.docker.compose labels.

This extra step makes managing large sets of containers cumbersome, especially when both docker-compose and docker run are used in parallel within a project or environment.

Proposed Solution

Add an indicator in the output of docker ps to differentiate containers based on their creation method. For example, this could include:

  • A new column (or a flag option to enable this column) that indicates Created by (docker-compose, docker run, etc.).
  • For containers created with docker-compose, also show the Compose project name and service name as additional columns (e.g., PROJECT/SERVICE).

Example output

CONTAINER ID   IMAGE       COMMAND      CREATED       STATUS       PORTS    CREATED BY        NAMES
abc123         nginx       "nginx -g…"  10 hours ago  Up 5 hours   ...      docker-compose    myapp_web_1
def456         redis       "redis-server" 5 hours ago Up 3 hours   ...      docker run        redis-container

Benefits

  1. Improved Clarity: Users can immediately tell which containers were created with docker-compose and which are standalone without needing to inspect each container manually.
  2. Better Management: It would make it easier to manage containers in mixed environments, especially when troubleshooting or cleaning up containers.
  3. Saves Time: This would eliminate extra steps like running docker inspect or setting up custom naming schemes to differentiate container origins.

Considerations

  • This feature could be enabled by default or as an optional flag (e.g., docker ps --show-origin), depending on how cluttered the output might get in different scenarios.
  • Compatibility with containers created by other orchestration tools could also be considered.

Closing Thoughts

This feature would significantly enhance usability, especially for users who work with both docker-compose and docker run. It would improve container management and make the docker ps command more informative and user-friendly.

kha84 avatar Sep 19 '24 17:09 kha84

Hi @kha84, thanks for the contribution!

I definitely agree, and we've actually been discussing improvements internally to things such as the image list and other commands, particularly regarding integrations with plugins (such as your Compose suggestion) – ideally, IMO, since Compose is the plugin that know about the annotations it sets, Compose could enhance the container list output for these containers.

We have to have some discussion in terms of how to implement this, but IMO this is something we'd like to do, just need to figure out how/do it.

I'll share internally as well :).

laurazard avatar Sep 20 '24 10:09 laurazard

@laurazard is this issue open to contribute ?

0xV0YD avatar Jan 21 '25 16:01 0xV0YD