# How to run a Docker Container as a daemon with Ansible?

**URL:** <https://forum.ansible.com/t/how-to-run-a-docker-container-as-a-daemon-with-ansible/17209>\
**Category:** Ansible Project\
**Created:** [January 7, 2015, 5:02pm UTC](https://forum.ansible.com/t/how-to-run-a-docker-container-as-a-daemon-with-ansible/17209 "2015-01-07T17:02:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dimitrios\_Alexiou](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dimitrios\_Alexiou](https://forum.ansible.com/u/Dimitrios_Alexiou)\
**Post date:** [January 7, 2015, 5:02pm UTC](https://forum.ansible.com/t/how-to-run-a-docker-container-as-a-daemon-with-ansible/17209/1 "2015-01-07T17:02:36Z")

</div>

Hello to everyone,

I came across this issue and until now I haven’t found a practical solution.

When running normally on my docker host this commad: docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock -t dalexiou/nginx\_docker-gen

I am spinning up a container as a daemon.

Now I have a playbook to automate this process. This playbook creates a directory on the host I want to spin up the container, puts inside the Dockerfile. Executes the Dockerfile to build the image and finally run the image to start a daemon container.

---

<div class="post-metadata">

**Author:** ![louis\_gueye](https://avatars.discourse-cdn.com/v4/letter/l/838e76/32.png) [@louis\_gueye](https://forum.ansible.com/u/louis_gueye)\
**Post date:** [January 19, 2015, 9:43am UTC](https://forum.ansible.com/t/how-to-run-a-docker-container-as-a-daemon-with-ansible/17209/2 "2015-01-19T09:43:31Z")

</div>

Hi Dimitrios,

The docker module works fine and by default the daemon option is true.  
The command/entrypoint of your Dockerfile must never return if you want to run as daemon.  
It has nothing to do with Ansible.  
First do the following:

- run your docker process via command line (in daemon mode)
- check that it runs properly (docker ps -a)
- check the logs (docker logs \<container\_id\>)

I did the same mistake when using docker. For instance to run mysql I thought running “service mysql start” would do the trick. But the “service” command starts the mysqld\_safe process **and returns.** So even if I ask for a daemon mode it will always return.  
The way to go was to run the /usr/bin/mysqld\_safe command.  
Check that you run the daemon process, not a wrapper around it: you should get better results.

Regards,

Louis
