# How can I use docker\_secrets in docker\_container?

**URL:** <https://forum.ansible.com/t/how-can-i-use-docker-secrets-in-docker-container/34952>\
**Category:** Ansible Project\
**Created:** [April 9, 2021, 1:10pm UTC](https://forum.ansible.com/t/how-can-i-use-docker-secrets-in-docker-container/34952 "2021-04-09T13:10:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fettheit](https://avatars.discourse-cdn.com/v4/letter/f/858c86/32.png) [@Fettheit](https://forum.ansible.com/u/Fettheit)\
**Post date:** [April 9, 2021, 1:10pm UTC](https://forum.ansible.com/t/how-can-i-use-docker-secrets-in-docker-container/34952/1 "2021-04-09T13:10:54Z")

</div>

Hi,

is there a way I can use docker\_secrets within docker\_container?  
If this is not possible maybe someone could help me with this:  
I want to configure the initial admin-password of a container. Therefore I can use a mounted file in the container (for example docker secret) or an encrypted string (htpasswd) as a command argument. I only want to store the plain password in the ansible vault, not the encrypted version or an additional file on disk.

Thanks for your help 🙂

---

<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:** [April 11, 2021, 1:37pm UTC](https://forum.ansible.com/t/how-can-i-use-docker-secrets-in-docker-container/34952/2 "2021-04-11T13:37:59Z")

</div>

Hi,

I'm not sure this is possible at all.

docker\_secret is a module for Docker's swarm mode. docker\_container is  
a module for Docker's non-swarm mode. If you use docker\_swarm\_service  
to manage a Docker swarm service, you can specify the secrets to use.

I also cannot find any reference to secrets when looking at the `docker  
run` help (which uses the same APIs as the docker\_container module  
does).

Cheers,  
Felix

---

<div class="post-metadata">

**Author:** ![Fettheit](https://avatars.discourse-cdn.com/v4/letter/f/858c86/32.png) [@Fettheit](https://forum.ansible.com/u/Fettheit)\
**Post date:** [April 11, 2021, 5:35pm UTC](https://forum.ansible.com/t/how-can-i-use-docker-secrets-in-docker-container/34952/3 "2021-04-11T17:35:41Z")

</div>

Surely not best practice, but with Portainer I could use secrets in my local stack without being in a Swarm-Cluster. It works great and I thought it would be nice to recreate my stack in Ansible to go a step further to automate additional tasks outside Docker-compose
