<p>@relik yes it is exactly as you point out. Docker is sending SIGKILL after 10 seconds.</p>
<p>In docker compose you can set <code>stop_grace_period:10m</code> and this bumps it up to waiting 10 minutes before issuing SIGKILL.</p>
<p>Also need to be careful if you are launching bitcoind from a bash script (as I was doing) you need to prepend it with <code>exec</code> command so that it receives the SIGTERM from docker.</p>

CC BY-SA 4.0
2024-07-21T11:17:19.623Z
2024-07-21T11:17:19.623Z
Fox Silver
<p>Best way to stop <code>bitcoind</code> is either by calling the JSONRPC interface with the <code>stop</code> command or by issuing a <code>SIGTERM</code> or <code>SIGHUP</code>.</p>

<p>But it may take a couple of seconds to shut down Bitcoin Core since it eventually has to write larger amount of data (time depends on your dbcache, disk-speed, mempool size, etc.).</p>

<p>So the environment layer (docker in your case) must be capable to take this into account (a slow process shutdown).</p>

CC BY-SA 3.0
2018-03-04T04:51:36.773Z
Thanks! I think docker stop actually issues a SIGTERM, but it likely does a SIGKILL after 10 seconds, which could be the crux of the problem. Would love to vote you up, but i'm at 14 rep =\
relik
CC BY-SA 3.0
2018-03-04T04:44:32.787Z
2018-03-04T04:44:32.787Z
Jonas Schnelli
<p>When I issue <code>docker stop &lt;id&gt;</code>, the process doesn't exit cleanly and <code>bitcoind</code> has to roll-forward blocks on the next startup. </p>

<pre><code>018-03-04 04:15:25 Rolling forward 0000000000000000001728efc81b210835048a7321ba3ec93197f698fac080ab (511863)
2018-03-04 04:15:26 Rolling forward 0000000000000000002be2e2792facd65e2358f874bc48f6410b80ecc8a6e756 (511864)
2018-03-04 04:15:26 Rolling forward 0000000000000000004740c4832b47a1c852db87cf4b9aea559db8712d2971a5 (511865)
</code></pre>

<p>This seems to be an issue with the <code>dbcache</code> not being written to disk prior to exit. I'm not sure if it's issuing a SIGTERM and then SIGKILL. </p>

<p>What is the best way to stop bitcoind to prevent any database related issues?</p>

CC BY-SA 3.0
2018-03-04T05:01:54.953Z
I found this to be very useful: https://www.ctl.io/developers/blog/post/gracefully-stopping-docker-containers/
relik
CC BY-SA 3.0
2018-03-04T06:52:36.840Z
Welcome to Bitcoin.SE! You can help the site by marking answers as accepted if they are correct and address the question so that the question does not remain as "unanswered".
Willtech
<bitcoin-core><bitcoind>
Graceful way to stop bitcoind in Docker container?
relik
# Graceful way to stop bitcoind in Docker container?

(Asked by: username_0 on 2018-03-04)

When I issue `docker stop <id>`, the process doesn't exit cleanly and `bitcoind` has to roll-forward blocks on the next startup.

```
018-03-04 04:15:25 Rolling forward 0000000000000000001728efc81b210835048a7321ba3ec93197f698fac080ab (511863)
2018-03-04 04:15:26 Rolling forward 0000000000000000002be2e2792facd65e2358f874bc48f6410b80ecc8a6e756 (511864)
2018-03-04 04:15:26 Rolling forward 0000000000000000004740c4832b47a1c852db87cf4b9aea559db8712d2971a5 (511865)

```

This seems to be an issue with the `dbcache` not being written to disk prior to exit. I'm not sure if it's issuing a SIGTERM and then SIGKILL.

What is the best way to stop bitcoind to prevent any database related issues?

**Tags:** bitcoin-core, bitcoind

> **Comments:**
> **username_0**: I found this to be very useful: https://www.ctl.io/developers/blog/post/gracefully-stopping-docker-containers/  
> **username_1**: Welcome to Bitcoin.SE! You can help the site by marking answers as accepted if they are correct and address the question so that the question does not remain as "unanswered".  

---

## 2 answers

### Answer by username_3 on 2018-03-04. Score: 4 | Accepted answer

Best way to stop `bitcoind` is either by calling the JSONRPC interface with the `stop` command or by issuing a `SIGTERM` or `SIGHUP`.

But it may take a couple of seconds to shut down Bitcoin Core since it eventually has to write larger amount of data (time depends on your dbcache, disk-speed, mempool size, etc.).

So the environment layer (docker in your case) must be capable to take this into account (a slow process shutdown).

> **Comments:**
> **username_0**: Thanks! I think docker stop actually issues a SIGTERM, but it likely does a SIGKILL after 10 seconds, which could be the crux of the problem. Would love to vote you up, but i'm at 14 rep =\  

---

### Answer by username_2 on 2024-07-21. Score: 0

@username_0 yes it is exactly as you point out. Docker is sending SIGKILL after 10 seconds.

In docker compose you can set `stop_grace_period:10m` and this bumps it up to waiting 10 minutes before issuing SIGKILL.

Also need to be careful if you are launching bitcoind from a bash script (as I was doing) you need to prepend it with `exec` command so that it receives the SIGTERM from docker.


---

