# docker\_container moduel fails to keep alive consul container

**URL:** <https://forum.ansible.com/t/docker-container-moduel-fails-to-keep-alive-consul-container/22317>\
**Category:** Ansible Project\
**Created:** [August 18, 2016, 2:31pm UTC](https://forum.ansible.com/t/docker-container-moduel-fails-to-keep-alive-consul-container/22317 "2016-08-18T14:31:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Agusti\_Tomas](https://avatars.discourse-cdn.com/v4/letter/a/6bbea6/32.png) [@Agusti\_Tomas](https://forum.ansible.com/u/Agusti_Tomas)\
**Post date:** [August 18, 2016, 2:31pm UTC](https://forum.ansible.com/t/docker-container-moduel-fails-to-keep-alive-consul-container/22317/1 "2016-08-18T14:31:11Z")

</div>

Hello,

I have a simple role called consul:

- name: Pull consul image  
docker\_image:  
name: consul  
tag: latest  
state: present

- name: Start consul container  
docker\_container:  
name: consul  
image: consul  
state: started  
published\_ports:

- 8500:8500

- 8301:8301

- 8300:8300  
hostname: “{{ ansible\_hostname }}”  
command: -d --name consul consul agent -server -bootstrap -ui -client=0.0.0.0

Which in my tests I have slimmed down to:

- name: Pull consul image  
docker\_image:  
name: consul  
tag: latest  
state: present

- name: Start consul container  
docker\_container:  
name: consul  
image: consul  
state: started  
command: consul

And which fails to start, and keep started the consul container. This is the log for the container (/var/lib/docker/containers/889833…/889833…-json.log):

[root@buildmaster 88983353e734e11b700d0f480318d76a1565de6ab474ca7a2da66915917ec87b]# more 88983353e734e11b700d0f480318d76a1565de6ab474ca7a2da66915917ec87b-json.log  
{“log”:“usage: consul [–version] [–help] \u003ccommand\u003e [\u003cargs\u003e]\n”,“stream”:“stderr”,“time”:“2016-08-18T14:12:17.207230775Z”}  
{“log”:“\n”,“stream”:“stderr”,“time”:“2016-08-18T14:12:17.207282204Z”}  
{“log”:“Available commands are:\n”,“stream”:“stderr”,“time”:“2016-08-18T14:12:17.207287432Z”}  
{“log”:" agent Runs a Consul agent\n",“stream”:“stderr”,“time”:“2016-08-18T14:12:17.207290787Z”}  
{“log”:" configtest Validate config file\n",“stream”:“stderr”,“time”:“2016-08-18T14:12:17.207294201Z”}  
{“log”:" event Fire a new event\n",“stream”:“stderr”,“time”:“2016-08-18T14:12:17.207297315Z”}  
{“log”:" exec Executes a command on Consul nodes\n",“stream”:“stderr”,“time”:“2016-08-18T14:12:17.207300479Z”}  
{“log”:" force-leave Forces a member of the cluster to enter the "left" state\n",“stream”:“stderr”,“time”:“2016-08-18T14:12:17.207303493Z”}  
{“log”:" info Provides debugging information for operators\n",“stream”:“stderr”,“time”:“2016-08-18T14:12:17.207306719Z”}  
{“log”:" join Tell Consul agent to join cluster\n",“stream”:“stderr”,“time”:“2016-08-18T14:12:17.207310573Z”}  
{“log”:" keygen Generates a new encryption key\n",“stream”:“stderr”,“time”:“2016-08-18T14:12:17.207313436Z”}  
{“log”:" keyring Manages gossip layer encryption keys\n",“stream”:“stderr”,“time”:“2016-08-18T14:12:17.2073163Z”}  
{“log”:" leave Gracefully leaves the Consul cluster and shuts down\n",“stream”:“stderr”,“time”:“2016-08-18T14:12:17.207319309Z”}  
{“log”:" lock Execute a command holding a lock\n",“stream”:“stderr”,“time”:“2016-08-18T14:12:17.207322275Z”}  
{“log”:" maint Controls node or service maintenance mode\n",“stream”:“stderr”,“time”:“2016-08-18T14:12:17.207325095Z”}  
{“log”:" members Lists the members of a Consul cluster\n",“stream”:“stderr”,“time”:“2016-08-18T14:12:17.207327983Z”}  
{“log”:" monitor Stream logs from a Consul agent\n",“stream”:“stderr”,“time”:“2016-08-18T14:12:17.207330872Z”}  
{“log”:" reload Triggers the agent to reload configuration files\n",“stream”:“stderr”,“time”:“2016-08-18T14:12:17.207333683Z”}  
{“log”:" rtt Estimates network round trip time between nodes\n",“stream”:“stderr”,“time”:“2016-08-18T14:12:17.207336563Z”}  
{“log”:" version Prints the Consul version\n",“stream”:“stderr”,“time”:“2016-08-18T14:12:17.207339435Z”}  
{“log”:" watch Watch for changes in Consul\n",“stream”:“stderr”,“time”:“2016-08-18T14:12:17.207342305Z”}  
{“log”:“\n”,“stream”:“stderr”,“time”:“2016-08-18T14:12:17.207345139Z”}

So apparently the consul command I pass is not good (I also tried quotes around the command).

If I start the container manually with:

[vagrant@buildmaster ~]$ docker run -ti -p 8500:8500 -p 8301:8301 -p 8300:8300 --name consul consul agent -server -bootstrap -ui -client=0.0.0.0  
==\> WARNING: Bootstrap mode enabled! Do not enable unless necessary  
==\> Starting Consul agent…  
==\> Starting Consul agent RPC…  
==\> Consul agent running!  
Node name: ‘6b02f67046a8’  
Datacenter: ‘dc1’  
Server: true (bootstrap: true)  
Client Addr: 0.0.0.0 (HTTP: 8500, HTTPS: -1, DNS: 8600, RPC: 8400)  
Cluster Addr: 172.17.0.2 (LAN: 8301, WAN: 8302)  
Gossip encrypt: false, RPC-TLS: false, TLS-Incoming: false  
Atlas:

==\> Log data will now stream in as it occurs:

2016/08/18 14:30:29 [INFO] serf: EventMemberJoin: 6b02f67046a8 172.17.0.2  
2016/08/18 14:30:29 [INFO] serf: EventMemberJoin: 6b02f67046a8.dc1 172.17.0.2  
2016/08/18 14:30:29 [INFO] raft: Node at 172.17.0.2:8300 [Follower] entering Follower state  
2016/08/18 14:30:29 [INFO] consul: adding LAN server 6b02f67046a8 (Addr: 172.17.0.2:8300) (DC: dc1)  
2016/08/18 14:30:29 [INFO] consul: adding WAN server 6b02f67046a8.dc1 (Addr: 172.17.0.2:8300) (DC: dc1)  
2016/08/18 14:30:29 [ERR] agent: failed to sync remote state: No cluster leader  
2016/08/18 14:30:30 [WARN] raft: Heartbeat timeout reached, starting election  
2016/08/18 14:30:30 [INFO] raft: Node at 172.17.0.2:8300 [Candidate] entering Candidate state  
2016/08/18 14:30:30 [INFO] raft: Election won. Tally: 1  
2016/08/18 14:30:30 [INFO] raft: Node at 172.17.0.2:8300 [Leader] entering Leader state  
2016/08/18 14:30:30 [INFO] consul: cluster leadership acquired  
2016/08/18 14:30:30 [INFO] consul: New leader elected: 6b02f67046a8  
2016/08/18 14:30:30 [INFO] raft: Disabling EnableSingleNode (bootstrap)  
2016/08/18 14:30:30 [INFO] consul: member ‘6b02f67046a8’ joined, marking health alive  
2016/08/18 14:30:31 [INFO] agent: Synced service ‘consul’

It works! Also if I daemonize it.

Anyone sees any problem? Thanks!

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 19, 2016, 3:01pm UTC](https://forum.ansible.com/t/docker-container-moduel-fails-to-keep-alive-consul-container/22317/2 "2016-08-19T15:01:17Z")

</div>

Never used docker\_container, but this command seems weird. command: is the command to run inside the container, so "-d --name consul" should be deleted?

---

<div class="post-metadata">

**Author:** ![Werner\_Flamme](https://avatars.discourse-cdn.com/v4/letter/w/c68b51/32.png) [@Werner\_Flamme](https://forum.ansible.com/u/Werner_Flamme)\
**Post date:** [August 19, 2016, 3:20pm UTC](https://forum.ansible.com/t/docker-container-moduel-fails-to-keep-alive-consul-container/22317/3 "2016-08-19T15:20:12Z")

</div>

Kai Stian Olstad [19.08.2016 17:01]:
