# Docker Entrypoint

**URL:** <https://forum.ansible.com/t/docker-entrypoint/33921>\
**Category:** Ansible Project\
**Created:** [September 29, 2020, 11:50am UTC](https://forum.ansible.com/t/docker-entrypoint/33921 "2020-09-29T11:50:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dave\_Gilmore](https://avatars.discourse-cdn.com/v4/letter/d/b77776/32.png) [@Dave\_Gilmore](https://forum.ansible.com/u/Dave_Gilmore)\
**Post date:** [September 29, 2020, 11:50am UTC](https://forum.ansible.com/t/docker-entrypoint/33921/1 "2020-09-29T11:50:15Z")

</div>

Hi Everyone,

I am trying to convert big old monolith bash script to ansible, and I’m about 90% of the way there.

I am having a bit of trouble with one element, the docker entrypoint.

The original code along with my Ansible attempt and the entrypoint debug output is here: [https://pastebin.com/J1j49aKT](https://pastebin.com/J1j49aKT)

I _think_ I have done everything correctly, but I do not get a populated license file

I’m sure there is something glaringly obvious, but I can’t seem to put my finger on it.

Thanks,

Dave

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [September 29, 2020, 12:10pm UTC](https://forum.ansible.com/t/docker-entrypoint/33921/2 "2020-09-29T12:10:43Z")

</div>

Hi,

> I am trying to convert big old monolith bash script to ansible, and  
> I'm about 90% of the way there.
> 
> I am having a bit of trouble with one element, the docker entrypoint.
> 
> The original code along with my Ansible attempt and the entrypoint  
> debug output is here: [https://pastebin.com/J1j49aKT](https://pastebin.com/J1j49aKT)
> 
> I \*think\* I have done everything correctly, but I do not get a  
> populated license file
> 
> I'm sure there is something glaringly obvious, but I can't seem to  
> put my finger on it.

you are relying on the bash shell to quote arguments for you correctly.  
Ansible won't do such magic for you.

The `entrypoint` option expects a list of strings; if it is not a list  
but a single string, it is treated as a comma-separated concatenated  
list, i.e. split by commas. In your case, you end up with a single  
string containing the whole command line. This is passed to docker as  
the executable to run in your container, which will obviously fail.

You have to compose a proper `entrypoint` list.

Also, the redirect is not part of the thing docker should execut, but  
something you have to handle on ansible level (i.e. ask the  
docker\_container module to capture stdout for you).

Cheers,  
Felix

---

<div class="post-metadata">

**Author:** ![Dave\_Gilmore](https://avatars.discourse-cdn.com/v4/letter/d/b77776/32.png) [@Dave\_Gilmore](https://forum.ansible.com/u/Dave_Gilmore)\
**Post date:** [September 29, 2020, 12:11pm UTC](https://forum.ansible.com/t/docker-entrypoint/33921/3 "2020-09-29T12:11:29Z")

</div>

Whoops, upon further scrutiny, I have realised I should be using entrypoint, but command instead.

[https://docs.ansible.com/ansible/latest/collections/community/general/docker\_container\_module.html#parameter-command](https://docs.ansible.com/ansible/latest/collections/community/general/docker_container_module.html#parameter-command)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [October 1, 2020, 6:59am UTC](https://forum.ansible.com/t/docker-entrypoint/33921/4 "2020-10-01T06:59:25Z")

</div>

Hello,  
Sorry if it’s not the right place, I’m thinking my problem is little bit similar.

In guacamole install process, It’s suggest to do:  
**docker** run --rm guacamole/guacamole /opt/guacamole/bin/initdb.sh --mysql \> _initdb.sql_

I want to convert in proper way with ansible. This is my task:

- name: Extract SQL Guacamole  
community.general.docker\_container:  
name: guacamole-sql-extract  
image: “guacamole/guacamole:latest”  
container\_default\_behavior: no\_defaults  
command: “/opt/guacamole/bin/initdb.sh --mysql \> /srv/live/{{ app\_name }}/initdb.sql”

But not file SQL is output.  
I tried with **container\_default\_behavior: compatibility, entrypoint** instead of **command** but no more work.

When I tried docker run […] dry, it’s work.

Thanks

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [October 1, 2020, 6:22pm UTC](https://forum.ansible.com/t/docker-entrypoint/33921/5 "2020-10-01T18:22:38Z")

</div>

Hi,

> Sorry if it's not the right place, I'm thinking my problem is little  
> bit similar.
> 
> In guacamole install process, It's suggest to do:  
> \*docker\* run --rm guacamole/guacamole /opt/guacamole/bin/initdb.sh  
> --mysql  
> \> \*initdb.sql\*

the stdout redirect is NOT part of the command executed by docker. It  
is part of the execution of the docker CLI tool itself.

> I want to convert in proper way with ansible. This is my task:
> 
> - name: Extract SQL Guacamole  
> community.general.docker\_container:  
> name: guacamole-sql-extract  
> image: "guacamole/guacamole:latest"  
> container\_default\_behavior: no\_defaults  
> command: "/opt/guacamole/bin/initdb.sh --mysql \> /srv/live/{{  
> app\_name }}/initdb.sql"

This is wrong. You need to remove the "\> /srv/...", and pass the  
`detach: false` option to docker\_container to enable non-detaching and  
stdout capturing. Then you need to register the output of the task, and  
extract the output from there as `result.container.Output`.

Also, your command line specifies `--rm`, which is equivalent to  
`auto_remove: true`.

Cheers,  
Felix

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [October 2, 2020, 4:08pm UTC](https://forum.ansible.com/t/docker-entrypoint/33921/6 "2020-10-02T16:08:51Z")

</div>

Hello,  
Thanks, but without argument, docker ansible failed.

- name: Extract SQL Guacamole  
community.general.docker\_container:  
name: guacamole-sql-extract  
image: “guacamole/guacamole:latest”  
container\_default\_behavior: no\_defaults  
detach: false

# command: “/opt/guacamole/bin/initdb.sh --mysql \> initdb.sql”

register: sqlextract

And when I let command and detach false, same error :  
“msg”: “Wrong number of arguments.\nUSAGE: /opt/guacamole/bin/initdb.sh [–postgres | --mysql]\nWrong number of arguments.\nUSAGE: /opt/guacamole/bin/initdb.sh [–postgres | --mysql]\nWrong number of arguments.\nUSAGE: /opt/guacamole/bin/initdb.sh [–postgres | --mysql]\nWrong number of arguments.\nUSAGE: /opt/guacamole/bin/initdb.sh [–postgres | --mysql]\nWrong number of arguments.\nUSAGE: /opt/guacamole/bin/initdb.sh [–postgres | --mysql]\nWrong number of arguments.\nUSAGE: /opt/guacamole/bin/initdb.sh [–postgres | --mysql]\n”,  
“status”: 1

I have to set command to get work.

May I used volume, but how? Because with dry run docker run, it extract in the folder in argument.

I don’t know… Sorry.
