Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

431
Views
How can i force remove a docker container using 'docker_container' module of Ansible?

I am having problems removing containers from my docker host after introducing cadvisor - https://github.com/google/cadvisor/issues/771

I have a large number of Ansible (2.2.1.0) scripts that i use to install my service containers on these docker host and internally they are using the docker_container module. Many times these scripts would want to remove a container, but because of the problem stated above, they are failing.

I can force kill docker container on these docker hosts easily:

docker rm container_name -fv

So i would expect that the force_kill option provided in the docker_container module (docker_container module docs) should be able to do the same:

- name: Delete  docker containers
  docker_container:
    name: "container_name"
    force_kill: true
    keep_volumes: false
    state: absent

But the script fail always. I do not know what is the purpose of this option if it is not able to force kill it. All of my scripts are failing even after enabling force_kill and i need to know how to make sure this option works as intended ?

Update: I now understand the force_kill option is sending the docker kill signal. I have updated the question to better reflect what i really want to achieve.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I think force_kill sends a kill signal as docker kill so

The main process inside the container will be sent SIGKILL, or any signal specified with option --signal.

I would check CMD and/or ENTRYPOINT in the Dockerfile of the image (if you used it) because

ENTRYPOINT and CMD in the shell form run as a subcommand of /bin/sh -c, which does not pass signals. This means that the executable is not the container’s PID 1 and does not receive Unix signals.

CMD ["/init.sh"] # exec form
CMD /init.sh     # shell form

Not sure this is the reason of your problem, but may be that a CMD in shell form doesn't forward the signal to your command.

As for Dominique Burton's blog

Always use the exec form if you want Docker to forward signals to your (sub-)process. This is not only important for sending custom signals to a Docker container, it’s also important to properly stop (i.e. docker stop) a container.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!