Libetwork提供一个原生Go实现的容器连接,是容器的网络。libetwork的目标是定义一个健壮的容器网络模型(CotaierNetworkModel),提供一个一致的编程接口和应用程序的网络抽象。
Libetwork一开始的代码只是libcotaier和DockerEgie中网络部分代码的合并,Docker官方的愿景是希望libetwork能像libcotaier一样,成为一个多平台的容器网络基础包。
受之前的一个GitHubissue启发,libetwork引入了容器网络模型(CNM)的概念,CNM定义了三个新的术语,分别是网络沙箱、Edpoit、Network。网络沙箱指的是在每一个容器中,将会有一个隔离的用于网络配置的环境。Edpoit是一个网络接口,可用于某一网络上的交流。Network是一个唯一的且可识别的Edpoit组。
接下来,Docker公司将会把libetwork集成到DockerEgie,并在DockerCLI中使用新的网络命令。具体的项目路线图读者可以参考GitHub。
注意:libetwork项目正在大力开发中,还不适合日常使用!
使用示例:
// Create a ew cotroller istace cotroller := libetwork.New() // Select ad cofigure the etwork driver etworkType := "bridge" driverOptios := optios.Geeric{} geericOptio := make(map[strig]iterface{}) geericOptio[optios.GeericData] = driverOptios err := cotroller.CofigureNetworkDriver(etworkType, geericOptio) if err != il { retur } // Create a etwork for cotaiers to joi. // NewNetwork accepts Variadic optioal argumets that libetwork ad Drivers ca make of etwork, err := cotroller.NewNetwork(etworkType, "etwork1") if err != il { retur } // For each ew cotaier: allocate IP ad iterfaces. The retured etwork // settigs will be used for cotaier ifos (ispect ad such), as well as // iptables rules for port publishig. This ifo is cotaied or accessible // from the retured edpoit. ep, err := etwork.CreateEdpoit("Edpoit1") if err != il { retur } // A cotaier ca joi the edpoit by providig the cotaier ID to the joi // api which returs the sadbox key which ca be used to access the sadbox // created for the cotaier durig joi. // Joi acceps Variadic argumets which will be made use of by libetwork ad Drivers _, err = ep.Joi("cotaier1", libetwork.JoiOptioHostame("test"), libetwork.JoiOptioDomaiame("docker.io")) if err != il { retur }
评论