4

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.

ishan
  • 1,202
  • 5
  • 24
  • 44

1 Answers1

2

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.

gile
  • 5,580
  • 1
  • 25
  • 31