docker-compose 如何加入固定网桥并指定静态 ip - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
brucmao
V2EX    Docker

docker-compose 如何加入固定网桥并指定静态 ip

  •  
  •   brucmao 2021-11-05 11:25:11 +08:00 1494 次点击
    这是一个创建于 1437 天前的主题,其中的信息可能已经有所发展或是发生改变。

    缘由: 我想在 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 里面怎么写

    第 1 条附言    2021-11-06 22:15:56 +08:00

    解决了,先删除 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 

    参考

    https://github.com/ericwang2006/docker_ttnode

    2 条回复    2021-11-11 13:51:26 +08:00
    brucmao
        1
    brucmao  
    OP
       2021-11-06 22:14:08 +08:00
    解决了,先删除 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
    asuraa
        2
    asuraa  
       2021-11-11 13:51:26 +08:00
    版本 3 好像不能直接 link 访问了
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2810 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 27ms UTC 13:31 PVG 21:31 LAX 06:31 JFK 09:31
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86