|
1 | | -# libnetwork |
2 | | -The Go package to manage Linux network namespaces |
| 1 | +# libnetwork - networking for containers |
| 2 | +Libnetwork provides a native Go implementation for connecting containers |
| 3 | + |
| 4 | +The goal of libnetwork is to deliver a robust Container Network Model that provides a consistent programming interface and the required network abstractions for applications. |
| 5 | + |
| 6 | +**NOTE**: libnetwork project is under heavy development and is not ready for general use. |
| 7 | + |
| 8 | +#### Current Status |
| 9 | +Please watch this space for updates on the progress. |
| 10 | + |
| 11 | +Currently libnetwork is nothing more than an attempt to modularize the Docker platform's networking subsystem by moving it into libnetwork as a library. |
| 12 | + |
| 13 | +Please refer to the [roadmap](ROADMAP.md) for more information. |
| 14 | + |
| 15 | +#### Using libnetwork |
| 16 | + |
| 17 | +There are many networking solutions available to suit a broad range of use-cases. libnetwork uses a driver / plugin model to support all of these solutions while abstracting the complexity of the driver implementations by exposing a simple and consistent Network Model to users. |
| 18 | + |
| 19 | +```go |
| 20 | +//Create a network for containers to join. |
| 21 | +network, err := libnetwork.NewNetwork("simplebridge", &Options{}) |
| 22 | +if err != nil { |
| 23 | + return err |
| 24 | +} |
| 25 | +// |
| 26 | +// For a new container: create network namespace (providing the path). |
| 27 | +networkPath := "/var/lib/docker/.../4d23e" |
| 28 | +networkNamespace, err := libnetwork.NewNetworkNamespace(networkPath) |
| 29 | +if err != nil { |
| 30 | + return err |
| 31 | +} |
| 32 | +// |
| 33 | +// For each new container: allocate IP and interfaces. The returned network |
| 34 | +// settings will be used for container infos (inspect and such), as well as |
| 35 | +// iptables rules for port publishing. |
| 36 | +interfaces, err := network.Link(containerID) |
| 37 | +if err != nil { |
| 38 | + return err |
| 39 | +} |
| 40 | +// |
| 41 | +// Add interfaces to the namespace. |
| 42 | +for _, interface := range interfaces { |
| 43 | + if err := networkNamespace.AddInterface(interface); err != nil { |
| 44 | + return err |
| 45 | + } |
| 46 | +} |
| 47 | +// |
| 48 | +``` |
| 49 | + |
| 50 | +## Future |
| 51 | +See the [roadmap](ROADMAP.md). |
3 | 52 |
|
4 | 53 | ## Contributing |
5 | 54 |
|
6 | 55 | Want to hack on libnetwork? [Docker's contributions guidelines](https://github.com/docker/docker/blob/master/CONTRIBUTING.md) apply. |
7 | 56 |
|
| 57 | +## Copyright and license |
| 58 | +Code and documentation copyright 2015 Docker, inc. Code released under the Apache 2.0 license. Docs released under Creative commons. |
| 59 | + |
0 commit comments