1. 出现该问题是因为只有使用–subnet创建的网络才能指定静态IP
    2. 如下使用–subnet创建网络(用来指定ip段),–gateway(用来指定网关),my_net3为创建的名字
    3. docker network create --driver bridge --subnet 172.22.1.0/24 --gateway 172.22.1.1 my_net
    4. ————————————————
    5. 版权声明:本文为CSDN博主「艾维巴蒂」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    6. 原文链接:https://blog.csdn.net/weixin_41634738/article/details/105113259
    1. version: "3.9"
    2. services:
    3. test:
    4. container_name: test
    5. image: registry.cn-hangzhou.aliyuncs.com/lwmacct/ubuntu:v20.04-t2022020101
    6. restart: always
    7. networks:
    8. default:
    9. ipv4_address: 172.22.1.100
    10. command:
    11. - 'tail'
    12. - '-f'
    13. - '/dev/null'
    14. volumes:
    15. - "/proc:/host"
    16. - "/data/kuaicdn/network/netns-v2.x-ctrl/link/public:/apps/public/"
    17. - "/data/kuaicdn/network/netns-v2.x-ctrl/link/882dbe9d0344:/apps/data/"
    18. environment:
    19. MAC: "88:2d:be:9d:03:44"
    20. VLAN: "0"
    21. IP_MASK: "192.168.1.101/24"
    22. GATEWAY: "192.168.1.1"
    23. BRIDGE: "br-ikuai-lan1"
    24. MAX_TX: "2000"
    25. MAX_RX: "2000"
    26. ENABLE: "1"
    27. networks:
    28. default:
    29. external:
    30. name: my_net