# Fast way to disconnect all connected peers

**URL:** <https://discuss.ipfs.tech/t/fast-way-to-disconnect-all-connected-peers/4247>\
**Category:** Help\
**Tags:** go-ipfs\
**Created:** [November 11, 2018, 9:43pm UTC](https://discuss.ipfs.tech/t/fast-way-to-disconnect-all-connected-peers/4247 "2018-11-11T21:43:18Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![plexus](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/plexus/32/1203_2.png) [@plexus](https://discuss.ipfs.tech/u/plexus)\
**Post date:** [November 11, 2018, 9:43pm UTC](https://discuss.ipfs.tech/t/fast-way-to-disconnect-all-connected-peers/4247/1 "2018-11-11T21:43:18Z")

</div>

Is there one?  
Because creating a script and disconnecting them one-by-one is quite slow.

---

<div class="post-metadata">

**Author:** ![koalalorenzo](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/koalalorenzo/32/745_2.png) [@koalalorenzo](https://discuss.ipfs.tech/u/koalalorenzo)\
**Post date:** [November 11, 2018, 10:06pm UTC](https://discuss.ipfs.tech/t/fast-way-to-disconnect-all-connected-peers/4247/2 "2018-11-11T22:06:19Z")

</div>

I am not sure, but you could ideally start the daemon in offline mode (use the option: `--offline`)

From the docs:

```auto
  --offline bool - Run offline. Do not connect to the rest of the network but provide local API.

```

---

<div class="post-metadata">

**Author:** ![plexus](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/plexus/32/1203_2.png) [@plexus](https://discuss.ipfs.tech/u/plexus)\
**Post date:** [November 11, 2018, 11:23pm UTC](https://discuss.ipfs.tech/t/fast-way-to-disconnect-all-connected-peers/4247/3 "2018-11-11T23:23:37Z")

</div>

@koalalorenzo my goal is to create a private ipfs network with no external peers, using docker.  
if i use `--offline=true` param, is it possible to later set it to `true` without shutting down the daemon?  
With `ipfs shutdown` the docker container shuts down too, so it wont help.

---

<div class="post-metadata">

**Author:** ![stebalien](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/stebalien/32/156_2.png) [@stebalien](https://discuss.ipfs.tech/u/stebalien)\
**Post date:** [November 12, 2018, 10:31pm UTC](https://discuss.ipfs.tech/t/fast-way-to-disconnect-all-connected-peers/4247/4 "2018-11-12T22:31:03Z")

</div>

1. You’ll need to specify your own bootstrap nodes (see the `ipfs bootstrap` commands). Otherwise, you’ll connect to the rest of the network automatically.
2. You _may_ want to turn off local discovery as well: [https://github.com/ipfs/go-ipfs/blob/master/docs/config.md#discovery](https://github.com/ipfs/go-ipfs/blob/master/docs/config.md#discovery)
3. You should consider using private networks: [https://github.com/ipfs/go-ipfs/blob/master/docs/experimental-features.md#private-networks](https://github.com/ipfs/go-ipfs/blob/master/docs/experimental-features.md#private-networks)

---

<div class="post-metadata">

**Author:** ![plexus](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/plexus/32/1203_2.png) [@plexus](https://discuss.ipfs.tech/u/plexus)\
**Post date:** [November 13, 2018, 7:49pm UTC](https://discuss.ipfs.tech/t/fast-way-to-disconnect-all-connected-peers/4247/5 "2018-11-13T19:49:54Z")

</div>

Thanks @stebalien for the info.  
All these are very promising options but, since i am not very familiar with docker, i am having a hard time to apply them to my docker deployment.

For the “private network” feature to work, i need to put `swarm.key` into the ipfs directory. Is there a way for docker not to start the daemon automatically? So i will be able to plant the file into the container and then run the daemon manually.  
Also i cannot stop the daemon without shutting down the container.  
A `daemon restart` option would be awesome in this situation…

---

<div class="post-metadata">

**Author:** ![stebalien](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/stebalien/32/156_2.png) [@stebalien](https://discuss.ipfs.tech/u/stebalien)\
**Post date:** [November 14, 2018, 2:43am UTC](https://discuss.ipfs.tech/t/fast-way-to-disconnect-all-connected-peers/4247/6 "2018-11-14T02:43:51Z")

</div>

I believe the correct way to do this is to run:

```auto
docker run --entrypoint ipfs init

```

_Then_, you’d copy in your swarm key. _Then_, you’d start IPFS normally. However I’m not entirely sure if this’ll work.

---

<div class="post-metadata">

**Author:** ![plexus](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/plexus/32/1203_2.png) [@plexus](https://discuss.ipfs.tech/u/plexus)\
**Post date:** [November 14, 2018, 11:09am UTC](https://discuss.ipfs.tech/t/fast-way-to-disconnect-all-connected-peers/4247/7 "2018-11-14T11:09:29Z")

</div>

@stebalien this produces “executable not found” error.  
I managed to do it with: `docker run -di --entrypoint "sh" --name "ipfs" ipfs/go-ipfs`

But in docker-compose when i use “sh” as the entrypoint the container exits immediately.  
Is it possible to prevent this, in order to `docker exec` everything i need?

---

<div class="post-metadata">

**Author:** ![stebalien](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/stebalien/32/156_2.png) [@stebalien](https://discuss.ipfs.tech/u/stebalien)\
**Post date:** [November 15, 2018, 1:42am UTC](https://discuss.ipfs.tech/t/fast-way-to-disconnect-all-connected-peers/4247/8 "2018-11-15T01:42:51Z")

</div>

Can you just get a shell using the `-it` flag?

---

<div class="post-metadata">

**Author:** ![plexus](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/plexus/32/1203_2.png) [@plexus](https://discuss.ipfs.tech/u/plexus)\
**Post date:** [November 17, 2018, 8:31am UTC](https://discuss.ipfs.tech/t/fast-way-to-disconnect-all-connected-peers/4247/9 "2018-11-17T08:31:16Z")

</div>

@koalalorenzo @stebalien I finally avoided docker services and used plain containers.  
For anyone interested in setting up a private ipfs network, a way that works well and pretty fast on Docker is:

1. `docker run -dti --entrypoint "sh" --name "ipfsXX" ipfs/go-ipfs`
2. `docker exec ipfsXX ipfs init`
3. `docker exec ipfsXX ipfs bootstrap rm all`
4. `docker exec -dti ipfsXX ipfs daemon`

For debugging purposes you can have all configs and ids using:

- `docker exec ipfsXX cat /data/ipfs/config > configfileXX`
- `docker exec ipfsXX ipfs id -f="<id>" > idfileXX`

---

<div class="post-metadata">

**Author:** ![koalalorenzo](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/koalalorenzo/32/745_2.png) [@koalalorenzo](https://discuss.ipfs.tech/u/koalalorenzo)\
**Post date:** [November 17, 2018, 8:48am UTC](https://discuss.ipfs.tech/t/fast-way-to-disconnect-all-connected-peers/4247/10 "2018-11-17T08:48:18Z")

</div>

You can directly mount a repository volume, and there you can customise your config file. No need to keep running `docker exec` 😃 I also strongly suggest to specify the docker tag, as the latest version is not always the stable one.

```auto
docker run -v $PWD/ipfs:/data/ipfs -it ipfs/go-ipfs:v0.4.18

```

Then you can modify the file as you wish and restart the container when you want.  
As an alternative you can just run a shell and run the commands from the container:

```auto
docker run -v $PWD/ipfs:/data/ipfs -it --entrypoint /bin/sh ipfs/go-ipfs:v0.4.18

```

Then you can run all the ipfs commands as you did, but without `docker exec ...` 😃

I hope it will help

---

<div class="post-metadata">

**Author:** ![plexus](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/plexus/32/1203_2.png) [@plexus](https://discuss.ipfs.tech/u/plexus)\
**Post date:** [November 17, 2018, 9:22am UTC](https://discuss.ipfs.tech/t/fast-way-to-disconnect-all-connected-peers/4247/11 "2018-11-17T09:22:15Z")

</div>

Volumes work like a charm under Linux, but under Windows are pure hell. Lots of errors.  
I do the above procedure only once (on deployment) using scripts, so it’s not a problem at all.  
The good thing with this implementation is that local dockerized peers auto discover each other, so you have a private network up and running in no time. 🎉

PS: Docker has its own feature for configuration files, which works pretty well under Windows too:

> **[Store configuration data using Docker Configs](https://docs.docker.com/engine/swarm/configs/)**
>
> About configs Docker 17.06 introduces swarm service configs, which allow you to store non-sensitive information, such as configuration files, outside a service’s image or running containers. This allows you to...

---

<div class="post-metadata">

**Author:** ![csunny](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/csunny/32/1489_2.png) [@csunny](https://discuss.ipfs.tech/u/csunny)\
**Post date:** [November 20, 2018, 9:53am UTC](https://discuss.ipfs.tech/t/fast-way-to-disconnect-all-connected-peers/4247/12 "2018-11-20T09:53:06Z")

</div>

Just like the zen of python say: Linux is better than windows.  
Give up windows and use Linux or Mac, you will save much time.

---

<div class="post-metadata">

**Author:** ![Anita2020](https://avatars.discourse-cdn.com/v4/letter/a/f04885/32.png) [@Anita2020](https://discuss.ipfs.tech/u/Anita2020)\
**Post date:** [September 12, 2020, 7:38am UTC](https://discuss.ipfs.tech/t/fast-way-to-disconnect-all-connected-peers/4247/13 "2020-09-12T07:38:56Z")

</div>

Yeah, I also tried in offline mode
