Skip to content

Improve detection of active containers to support docker-compose v2 #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

StephenBeirlaen
Copy link
Contributor

@StephenBeirlaen StephenBeirlaen commented Jul 27, 2021

On docker-compose v1.x, this is the output of run ps application:

              Name                        Command              State        Ports
-----------------------------------------------------------------------------------
<someproject>_application_1   /startup.sh php-fpm7.4   Up (healthy)   9000/tcp

On docker-compose v2.x (currently in beta), the same command returns:

              Name                        Command              State        Ports
-----------------------------------------------------------------------------------
<someproject>_application_1   /startup.sh php-fpm7.4   running (healthy)   9000/tcp

Note the running container state is listed as "running" instead of "Up" in the newer version. This breaks compatibility with the current active container detection logic.
Instead of searching for both "Up" and "running" (which might break again sooner or later), I suggest to --filter the run ps output to only show running containers.
--filter 'status=running' is compatible with docker-compose v1.x and v2.x.
I'm also passing the --services argument to return a list of only the docker-compose service names, that we can search through to find the required container and determine that it is running.

On docker-compose v2.x, docker ps lists running container states as "running" instead of "Up".
This breaks compatibility with the current detection logic.
Fixed by filtering on running containers (compatible with docker-compose v1.x and v2.x) and then checking whether the requested container is present in the returned list.
Copy link
Member

@BlackIkeEagle BlackIkeEagle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, did not yet check the full difference between docker-compose and the new docker compose which seem to be the same on macOS

@BlackIkeEagle BlackIkeEagle merged commit 5f5b20e into dockerwest:master Aug 19, 2021
@BlackIkeEagle
Copy link
Member

Thanks @StephenBeirlaen Nice work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants