在 Dockerized Syncthing 上本地发现设备的问题

在 Dockerized Syncthing 上本地发现设备的问题

我正在尝试设置一个 Syncthing 实例供本地使用,因此我不想运行发现服务器。对于设备的本地发现,Syncthing 通过其所连接网络的广播 IP 地址来宣传自己。问题是所有 docker 容器都驻留在 DockerNet 中,这是 Docker 的虚拟化网络。

这是ifconfig在我的主机上的结果。

root@deltastation:~# ifconfig
docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        inet6 fe80::42:d9ff:fe53:d961  prefixlen 64  scopeid 0x20<link>
        ether 02:42:d9:53:d9:61  txqueuelen 0  (Ethernet)
        RX packets 55574  bytes 71707185 (68.3 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 43881  bytes 3441923 (3.2 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.101  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::1dea:8489:d94a:35df  prefixlen 64  scopeid 0x20<link>
        ether 02:81:af:f1:00:09  txqueuelen 1000  (Ethernet)
        RX packets 45779  bytes 3638460 (3.4 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 62916  bytes 72948919 (69.5 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 38 

如您所见,dockerized syncthing 一直在 172.17.255.255 上宣传自己,而客户端位于 192.168.0.0 网络上。有什么办法可以修复它吗?

答案1

Syncthing 的自述文件-Docker.md状态:

为了允许本地发现,docker主机网络可以改用:

$ docker pull syncthing/syncthing
$ docker run --network=host \
    -v /wherever/st-sync:/var/syncthing \
    syncthing/syncthing:latest

正常运行的 Dockerstack.yml如下所示:

version: "3.7"
services:
  syncthing:
    image: "syncthing/syncthing"
    networks:
      hostnet: {}
    ports:
    - target: 8384
      published: 8384
      protocol: "tcp"
      mode: "host"
    - target: 22000
      published: 22000
      protocol: "tcp"
      mode: "host"
    - target: 21027
      published: 21027
      protocol: "udp"
      mode: "host"
    volumes:
    - "syncthing-data:/var/syncthing/"
    - "/mnt/Sync/:/mnt/Sync/"
networks:
  hostnet:
   external: true
   name: host

答案2

我用linuxserver.io syncthing docker 镜像。为了启用 syncthing 实例的本地发现,我调整了 docker-compose 配置并添加了以下network_mode: host行:

---
version: "2.1"
services:
  syncthing:
    image: linuxserver/syncthing
    container_name: syncthing
    hostname: syncthing #optional
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Europe/London
    volumes:
      - /path/to/appdata/config:/config
      - /path/to/data1:/data1
      - /path/to/data2:/data2
    ports:
      - 8384:8384
      - 22000:22000
      - 21027:21027/udp
    restart: unless-stopped
    network_mode: host

相关内容