# docker\_container - container stops without completing the commands

**URL:** <https://forum.ansible.com/t/docker-container-container-stops-without-completing-the-commands/36826>\
**Category:** Ansible Project\
**Created:** [July 11, 2022, 1:59pm UTC](https://forum.ansible.com/t/docker-container-container-stops-without-completing-the-commands/36826 "2022-07-11T13:59:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dulhaver](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dulhaver/32/1061_2.png) [@dulhaver](https://forum.ansible.com/u/dulhaver)\
**Post date:** [July 11, 2022, 1:59pm UTC](https://forum.ansible.com/t/docker-container-container-stops-without-completing-the-commands/36826/1 "2022-07-11T13:59:26Z")

</div>

I want to create a docker container on a remote host and then, in a second step build a binary for pgBackRest inside that container.  
It fails with the task to create the container, install some packages for the build and then remain to run.

- name: creating a build-container  
docker\_container:name: pgBackRestBuilder  
image: [docker.io/rockylinux:8](http://docker.io/rockylinux:8)  
volumes:
- /data/build/:/build  
state: started  
restart: true  
detach: true  
tty: true  
interactive: true  
working\_dir: /build  
command: dnf install -y make gcc openssl-devel libxml2-devel lz4-devel libzstd-devel bzip2-devel

become: true

What happens is that the container is being spun up, running for about 90 seconds and then shutting down without (as far as I can tell) having installed i.e. make. I was thinking the detach, tty & interactive options should have made the container to last.

any hint, what I am doing wrong here?

---

<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:** [July 11, 2022, 7:35pm UTC](https://forum.ansible.com/t/docker-container-container-stops-without-completing-the-commands/36826/2 "2022-07-11T19:35:39Z")

</div>

Hi,

I assume that running "dnf install -y make gcc openssl-devel  
libxml2-devel lz4-devel libzstd-devel bzip2-devel" is done after ~90  
seconds.

You are asking for that command to be run in a container, once that  
command finishes, the container exists. That's how Docker works, and it  
would behave exactly the same as the module if you start a detached  
container from the Docker CLI.

If you want the container to keep existing, you need to use a command  
that does not exit.

Basically what you ask the module to do is equivalent to running

&nbsp;&nbsp;docker run --detach --interactive --tty --workdir /build \  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-v /data/build/:/build --name pgBackRestBuilder \  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;docker.io/rockylinux:8 dnf install -y make gcc openssl-devel \  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;libxml2-devel lz4-devel libzstd-devel bzip2-devel

on the command line.

Cheers,  
Felix
