Docker network Create加–subnet后,使用docker network ls查看,在剛剛新建的網絡上沒看到driver,使用docker network inspect 查看詳細信息,會看到好多地方都沒數據,特別是driver,不加–subnet,一切又正常。
異常圖如下:


解決
解決:這時候你吧–subnet的網段換一個就好了。原因是–subnet指定的網段和某個network的網段沖突了。

補充知識:docker-compose文件中networks使用已經創建的網絡
前置條件:
docker版本為:18.06.1-ce,build e68fc7a
docker-compose版本:1.22.0,build f46880fe
使用已經存在的網絡
使用docker創建一個網絡。給出示例如下:
docker network create --driver=bridge --subnet=192.168.88.0/24 demo
執行命令查看網絡是否創建成功:
docker network ls
使用創建好的demo網絡,docker-compose.xml如下:
version: "3.7"
services:
cloudgo:
image: cloudgo:latest
container_name: cloudgo
ports:
- "8080:8080"
logging:
driver: "json-file"
options:
max-size: "1000k"
max-file: "20"
networks:
demo:
ipv4_address: 192.168.88.80
networks:
demo:
external: true
主要核心配置是:
networks:
demo:
external: true
該部分表示使用外部網絡demo,外部為true。至于重新創建網絡的核心配置為:
networks:
demo:
driver: default
config:
subnet: 172.16.238.0/24
gateway: 172.16.238.1
demo表示創建的網絡后綴,驅動(driver)設置為默認值,子網(subnet)為:172.16.238.0/24、網關(gateway)。
上述只是簡單講了下 在當前docker、docker-compose版本下進行上述配置是有效的,其他版本沒有嘗試過,上述方法不一定適用其他版本。希望能給大家一個參考,也希望大家多多支持腳本之家。