缘由: 我想在 nas 中用 docker 创建 qbittorrent 容器,并指定一个 ip,然后路由器设置这个 ip 走直连
1 、先创建 bridge-host 网络,参考的这里
docker network create -d macvlan --subnet=10.10.10.0/24 --gateway=10.10.10.10 -o parent=ovs_eth0 bridge-host
2 、创建 qbittorrent 容器并加入 bridge-host 网络,docker-compose 如下
version: '3' services: qbittorrent: image: linuxserver/qbittorrent:14.2.3.99202004172232-6962-29e9594ubuntu18.04.1-ls73 container_name: qbittorrent restart: always network_mode: bridge-host ports: - 8080:8080 - 53168:53168/udp - 53168:53168 environment: PUID: 1000 PGID: 1000 TZ: Asia/Shanghai UMASK_SET: 022 WEBUI_PORT: 8080 volumes: - /path/to/config:/config - /path/to/downloads:/downloads
怎么给这个容器指定一个静态 ip,我试过下面的方法
version: '3' services: qbittorrent: image: linuxserver/qbittorrent:14.2.3.99202004172232-6962-29e9594ubuntu18.04.1-ls73 container_name: qbittorrent restart: always networks: bridge-host: ipv4_address: 10.10.10.102 ports: - 8080:8080 - 53168:53168/udp - 53168:53168 environment: PUID: 1000 PGID: 1000 TZ: Asia/Shanghai UMASK_SET: 022 WEBUI_PORT: 8080 volumes: - /path/to/config:/config - /path/to/downloads:/downloads networks: bridge-host: ipam: config: - subnet: "10.10.10.0/24"
这样并不会成功,这样会创建 qbittorrent_bridge_host 网络,并且会失败,因为已经存在 10.10.10.0 这样子网了,
不过 docker 倒是可以启动的时候指定 ip
docker run -itd --restart=always --network bridge-host --ip=10.10.10.102 --name qbittorrent linuxserver/qbittorrent:14.2.3.99202004172232-6962-29e9594ubuntu18.04.1-ls73
就是不知道在 docker-compose 里面怎么写
解决了,先删除 bridge-host网络
docker network rm bridge-host
然后docker-compose 执行下面的
version: '2' services: qbittorrent: image: linuxserver/qbittorrent:14.2.3.99202004172232-6962-29e9594ubuntu18.04.1-ls73 container_name: qbittorrent restart: always networks: macvlan: ipv4_address: 10.10.10.102 environment: PUID: 1000 PGID: 1000 TZ: Asia/Shanghai UMASK_SET: 022 WEBUI_PORT: 8080 volumes: - /path/to/config:/config - /path/to/downloads:/downloads networks: macvlan: name: macvlan driver: macvlan driver_opts: parent: ovs_eth0 ipam: config: - subnet: 10.10.10.0/24 gateway: 10.10.10.10
参考
![]() | 1 brucmao OP 解决了,先删除 bridge-host 网络 ``` docker network rm bridge-host ``` 然后 docker-compose 执行下面的 ```yaml version: '2' services: qbittorrent: image: linuxserver/qbittorrent:14.2.3.99202004172232-6962-29e9594ubuntu18.04.1-ls73 container_name: qbittorrent restart: always networks: macvlan: ipv4_address: 10.10.10.102 environment: PUID: 1000 PGID: 1000 TZ: Asia/Shanghai UMASK_SET: 022 WEBUI_PORT: 8080 volumes: - /path/to/config:/config - /path/to/downloads:/downloads networks: macvlan: name: macvlan driver: macvlan driver_opts: parent: ovs_eth0 ipam: config: - subnet: 10.10.10.0/24 gateway: 10.10.10.10 ``` 参考 https://github.com/ericwang2006/docker_ttnode |
2 asuraa 2021-11-11 13:51:26 +08:00 版本 3 好像不能直接 link 访问了 |