Skip to content
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

state: healthy for docker_container #890

Closed
LeanderFS opened this issue Jun 18, 2024 · 2 comments · Fixed by #921
Closed

state: healthy for docker_container #890

LeanderFS opened this issue Jun 18, 2024 · 2 comments · Fixed by #921
Labels
docker-plain plain Docker (no swarm, no compose, no stack) enhancement New feature or request

Comments

@LeanderFS
Copy link

SUMMARY

Currently it's only possible to use state absent, present, stopped and started for the docker_container module. I would like to propose adding state: healthy to have Ansible wait until the integrated HEALTHCHECK returns healthy (when defined in the Dockerfile).

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

community.docker.docker_container

ADDITIONAL INFORMATION

By implementing this feature, a playbook can halt execution until the docker_container healtcheck returns healthy. This prevents additional tasks to poll for the health manually.

- name: Create database container
  docker_container:
    name: "database"
    image: "mysql:latest"
    state: "healthy" # This will trigger Ansible to wait for the HEALTHCHECK statement to return healthy, and fail if unhealthy.
    restart: true
    detach: true
    pull: "always"
    restart_policy: always
    published_ports:
      - "{{ db_fixture_port }}:3306"
@felixfontein felixfontein added enhancement New feature or request docker-plain plain Docker (no swarm, no compose, no stack) labels Jun 18, 2024
@felixfontein
Copy link
Collaborator

Another idea would be to (also) have a separate module which allows to wait for several contains at once to reach the healthy state. That would allow users to start several containers first with the docker_container module, and then wait until all of them are healthy afterwards. This is likely faster than waiting for each to be healthy before starting the next.

Your case can then also be split up into just two tasks (without any explicit polling).

Obviously that doesn't mean that a state=healthy (or something similar) doesn't make sense / shouldn't be implemented, I think it's just more flexible to also have a separate module for just waiting :)

@felixfontein
Copy link
Collaborator

I've implemented state=healthy in #921.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docker-plain plain Docker (no swarm, no compose, no stack) enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants