Stopping paused docker containers

In my multi-container application, I suspend containers that are not currently needed. When they are needed again, I dispute them. This works great.

However, if something goes wrong in one of the running containers (container exits with an exit code! = 0), docker-compose (which I also use) tries to stop all other containers. Once a container is suspended, it cannot be stopped or killed.

A small example to illustrate what is happening. (all these commands are automated in my case)

docker start cd1d8ad01f56
docker pause cd1d8ad01f56
docker stop cd1d8ad01f56

Error response from daemon: Cannot stop container cd1d8ad01f56: 
 Container cd1d8ad01f56c695a598e168e2eacdcd20a5231b9240029db1579bc0f1dcb903 
 is paused. Unpause the container before stopping
Error: failed to stop containers: [cd1d8ad01f56]

      

I want containers to be stopped even if they are suspended.

The solutions I was thinking about:

  • Disable each sleeping container first, then stop or kill it. This is an unsuitable solution that requires manual work. But it works ... I can write a script that looks for paused containers and then cancels and kills them. But I want to compose, to just kill everything else and be done with it. I don't want to issue another command to execute my script.

  • Is there a way to tell the container code that exits (i.e. tell it to disable other containers)? To prevent containers from sleeping when trying to stop them.

Disabling each sleeping container first, then stopping or killing, is a tedious job that I would like to automate. I'm working in a test environment and I don't care how containers are closed. I just want them to end up along with the failed containers.

+3


source to share





All Articles