# Docker module does not restart containers when docker parameters have changed

**URL:** <https://forum.ansible.com/t/docker-module-does-not-restart-containers-when-docker-parameters-have-changed/16322>\
**Category:** Ansible Project\
**Created:** [September 24, 2014, 4:11pm UTC](https://forum.ansible.com/t/docker-module-does-not-restart-containers-when-docker-parameters-have-changed/16322 "2014-09-24T16:11:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aaron\_Feng](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@Aaron\_Feng](https://forum.ansible.com/u/Aaron_Feng)\
**Post date:** [September 24, 2014, 4:11pm UTC](https://forum.ansible.com/t/docker-module-does-not-restart-containers-when-docker-parameters-have-changed/16322/1 "2014-09-24T16:11:37Z")

</div>

Currently the docker module only restarts the container if the name parameter is specified and the image has changed. Are there plans to also check if other docker parameters have changed such as env, port and volume?  
It is pretty common to pass in configuration information via environment variables to containers. It would be nice if the Ansible docker modules realizes docker parameters have changed, then automatically restart the container.  
I don’t think volume or port will change often but configuration information via environment variables will certainly evolve over time.

Aaron

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [September 24, 2014, 4:17pm UTC](https://forum.ansible.com/t/docker-module-does-not-restart-containers-when-docker-parameters-have-changed/16322/2 "2014-09-24T16:17:06Z")

</div>

There are no plans per se but that doesn’t mean it’s not a good idea.

I think it would depend on whether this was easily queryable by docker-py, but I imagine it would be.

If you’d like to work on this, you are welcome, otherwise please file a feature request in GitHub so we don’t lose track of the idea.

Thanks!

---

<div class="post-metadata">

**Author:** ![Aaron\_Feng](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@Aaron\_Feng](https://forum.ansible.com/u/Aaron_Feng)\
**Post date:** [October 1, 2014, 4:32pm UTC](https://forum.ansible.com/t/docker-module-does-not-restart-containers-when-docker-parameters-have-changed/16322/3 "2014-10-01T16:32:29Z")

</div>

Here’s the code change to restart the container if env vars have changed:

[https://github.com/forty9ten/ansible-modules-core/compare/ansible:devel...devel](https://github.com/forty9ten/ansible-modules-core/compare/ansible:devel...devel)

Let me know what you think.

I know in the previous post I also talked about also checking other parameters such as volume and port.  
Maybe that can be done as a separate PR. I believe just the environmental detection is useful on its own.

Aaron

---

<div class="post-metadata">

**Author:** ![Vasco\_Figueira](https://avatars.discourse-cdn.com/v4/letter/v/9f8e36/32.png) [@Vasco\_Figueira](https://forum.ansible.com/u/Vasco_Figueira)\
**Post date:** [October 2, 2014, 11:17am UTC](https://forum.ansible.com/t/docker-module-does-not-restart-containers-when-docker-parameters-have-changed/16322/4 "2014-10-02T11:17:22Z")

</div>

Hi Aron,

---

<div class="post-metadata">

**Author:** ![Aaron\_Feng](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@Aaron\_Feng](https://forum.ansible.com/u/Aaron_Feng)\
**Post date:** [October 2, 2014, 12:39pm UTC](https://forum.ansible.com/t/docker-module-does-not-restart-containers-when-docker-parameters-have-changed/16322/5 "2014-10-02T12:39:14Z")

</div>

Hi Vasco,

> Does that mean you do not experience  
> [https://github.com/ansible/ansible-modules-core/issues/27](https://github.com/ansible/ansible-modules-core/issues/27) ?

The issue I'm trying to tackle is slightly different than yours. My  
image:tag has not changed (ie, not using latest but actual version  
tag) but some other Docker parameters have changed within Ansible  
playbook. The code patch above only currently handles environment  
variables, but I plan to also handle port and volumes sometime today.

The issue you reference is also what I have been seeing, but it is not  
an issue for me because the tag and image are being changed at the  
same time.

Aaron

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [October 2, 2014, 8:51pm UTC](https://forum.ansible.com/t/docker-module-does-not-restart-containers-when-docker-parameters-have-changed/16322/6 "2014-10-02T20:51:47Z")

</div>

Just a note - please send in a PR if you have something, if you just send me the diff on your branch and master, we won’t have it in the list.

---

<div class="post-metadata">

**Author:** ![Aaron\_Feng](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@Aaron\_Feng](https://forum.ansible.com/u/Aaron_Feng)\
**Post date:** [October 2, 2014, 9:54pm UTC](https://forum.ansible.com/t/docker-module-does-not-restart-containers-when-docker-parameters-have-changed/16322/7 "2014-10-02T21:54:02Z")

</div>

Understood. I’m still working on it. I will definitely send PR when I am ready.

Aaron
