<p>I've run into similar issues with Docker Swarm and Daphne containers. Swarm's auto-healing doesn't always handle Daphne well, likely due to how it manages health checks. If <code>docker rm -f</code> or <code>docker service rm</code> aren’t working, try scaling the service down to zero first (<code>docker service scale &lt;service_name&gt;=0</code>), then remove it. If it's still stuck, restarting the Docker daemon sometimes helps clear things up.</p>

CC BY-SA 4.0
2024-08-29T16:34:02.580Z
**Found these answers** :



Locked Resources: Docker Swarm might lock resources that are still being used or in a deadlock situation, especially if the service is still running or managed by Swarm.

`docker service scale <service_name>=0
docker service rm <service_name>`

Unhealthy Containers: If a container is unhealthy, Swarm might continuously try to restart it, preventing removal.

`docker service update --force --restart-condition none <service_name>
docker service rm <service_name>`

Mostly **It have to be handle in ASGI API then Docker or Docker Swarm**
playwithcode
CC BY-SA 4.0
2024-08-29T13:30:22.203Z
2024-08-29T13:30:22.203Z
lostmarien
<p>I'm encountering an issue with Docker Swarm's auto-healing properties while using Django with Daphne. Typically, Docker Swarm should automatically heal containers, even if they become unhealthy. However, when my Daphne container in Docker Swarm goes into an unhealthy or healthy state, I face difficulties removing it forcefully.</p>
<p>Specifically, when I try to remove the container or the service using docker rm -f or docker service rm, the command doesn't work as expected, and I'm unable to remove the container or service. This issue only seems to occur with my Django + Daphne setup, as other containers don't exhibit this behavior.</p>
<p>Has anyone experienced similar issues with Docker Swarm and Daphne? How can I effectively manage or remove these containers when they become unhealthy?</p>
<blockquote>
<p>Any help or suggestions would be greatly appreciated!</p>
</blockquote>

CC BY-SA 4.0
2024-09-02T11:43:34.653Z
no idea if this is the case but containers that dont listen for kill messages can stall docker: add "init: true" to the docker compose for the service to see if it helps
Chris Becke
CC BY-SA 4.0
2024-09-02T12:52:00.583Z
`stop_grace_period: 60s  # Give 60 seconds to shut down gracefully`

by adding this in docker compose.

This is one of the solution for Latest Daphane v3+, in Older Daphne we have to handle by API logics
playwithcode
<docker><docker-compose><docker-swarm>
Issue with Removing Unhealthy or Healthy Django + Daphne Containers in Docker Swarm
playwithcode
# Issue with Removing Unhealthy or Healthy Django + Daphne Containers in Docker Swarm

(Asked by: username_0 on 2024-08-29)

I'm encountering an issue with Docker Swarm's auto-healing properties while using Django with Daphne. Typically, Docker Swarm should automatically heal containers, even if they become unhealthy. However, when my Daphne container in Docker Swarm goes into an unhealthy or healthy state, I face difficulties removing it forcefully.

Specifically, when I try to remove the container or the service using docker rm -f or docker service rm, the command doesn't work as expected, and I'm unable to remove the container or service. This issue only seems to occur with my Django + Daphne setup, as other containers don't exhibit this behavior.

Has anyone experienced similar issues with Docker Swarm and Daphne? How can I effectively manage or remove these containers when they become unhealthy?

> Any help or suggestions would be greatly appreciated!

**Tags:** docker, docker-compose, docker-swarm

> **Comments:**
> **username_1**: no idea if this is the case but containers that dont listen for kill messages can stall docker: add "init: true" to the docker compose for the service to see if it helps  
> **username_0**: `stop_grace_period: 60s  # Give 60 seconds to shut down gracefully`  by adding this in docker compose.  This is one of the solution for Latest Daphane v3+, in Older Daphne we have to handle by API logics  

---

## 1 answers

### Answer by username_2 on 2024-08-29. Score: 1

I've run into similar issues with Docker Swarm and Daphne containers. Swarm's auto-healing doesn't always handle Daphne well, likely due to how it manages health checks. If `docker rm -f` or `docker service rm` aren’t working, try scaling the service down to zero first (`docker service scale =0`), then remove it. If it's still stuck, restarting the Docker daemon sometimes helps clear things up.

> **Comments:**
> **username_0**: **Found these answers** :    Locked Resources: Docker Swarm might lock resources that are still being used or in a deadlock situation, especially if the service is still running or managed by Swarm.  `docker service scale <service_name>=0 docker service rm <service_name>`  Unhealthy Containers: If a container is unhealthy, Swarm might continuously try to restart it, preventing removal.  `docker service update --force --restart-condition none <service_name> docker service rm <service_name>`  Mostly **It have to be handle in ASGI API then Docker or Docker Swarm**  

---

