restart docker when mounted file changes

34 views
Skip to first unread message

Koen Janssens

unread,
Mar 18, 2016, 4:00:15 PM3/18/16
to Ansible Project
Hi, 

I have an ansible tasklist that generates a cfg file from a template first and then starts a docker container using that cfg file as a volume. 

Works fine. 

But when the generated cfg file changes (cfg file is actually generated from ansible inventory) , the docker container is not restarted, since from docker perspective nothing changed.Is there a way to 'force' ansible to restart the container under cetain conditions ? 

Thanks, 

Koen

Cfg: 

---
- template: "src=members.conf.j2 dest={{ docker_host_dir }}/members.conf"
- name: balancer
  docker:
     name: balancer
     image: <...>
     state: reloaded
     net: "{{ docker_net }}"
     ports:
     - "8000:8000"
     volumes:
     - "{{ docker_host_dir }}/members.conf:/usr/local/apache2/conf/members.conf"

Uditha Desilva

unread,
Mar 19, 2016, 5:41:00 AM3/19/16
to Ansible Project
Changing "state: restarted" (rather than reloaded) might be enough -- otherwise try adding a "notify" to the task that is creating the config file, and a "handler" to explicitly stop and then start the container.
Reply all
Reply to author
Forward
0 new messages