When using Ansible’sdocker_container to manage containers, we’ve seen people use wait_for ensure the container is started.

This requires that the container exposes a port and typically on the host network. Then the IP and the exposed/published port can be used to verify the container (or the service inside) is running.

What if there is no port, or no host binding?

If there is nothing to expose from the container (e.g. think of a queue worker), the following can be done:

name: Start a service without a port
    name: service_without_port
    image: whatever
  register: my_service_status
name: Save status
    container_is_running: «{{ my_service_status.ansible_facts.docker_container.State.Running }}«
    msg: «The service is not running«
  when: not container_is_running

If however you expose a port, but not on the host, then the following will help to grab the IP of the container and to be able to verify operation:

# assume this is preceeded by the docker_container module above
name: Get container IP
    container_ip: «{{ my_service_status.ansible_facts.docker_container.NetworkSettings.IPAddress }}«
name: Check container
    host: «{{ container_ip }}«
    port: 31337

Добавить комментарий

Ваш e-mail не будет опубликован. Обязательные поля помечены *

Любишь мемасики?

Подпишись на мой телеграм-канал!