docker_container - container stops without completing the commands

20 views
Skip to first unread message

dulh...@mailbox.org

unread,
Jul 11, 2022, 9:59:44 AM7/11/22
to ansible...@googlegroups.com
 
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
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?

Felix Fontein

unread,
Jul 11, 2022, 3:35:58 PM7/11/22
to ansible...@googlegroups.com
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

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

on the command line.

Cheers,
Felix
Reply all
Reply to author
Forward
0 new messages