Skip to content

Commit

Permalink
added basic docker 1.9 networking support
Browse files Browse the repository at this point in the history
  • Loading branch information
schmunk42 committed Dec 1, 2015
1 parent 7bc7ca9 commit fdf2922
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion GLOCKFILE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
github.com/BurntSushi/toml f87ce853111478914f0bcffa34d43a93643e6eda
github.com/Sirupsen/logrus 6ebb4e7b3c24b9fef150d7693e728cb1ebadf1f5
github.com/docker/docker 2606a2e4d3bf810ec82e373a6cd334e22e504e83
github.com/fsouza/go-dockerclient 1399676f53e6ccf46e0bf00751b21bed329bc60e
github.com/fsouza/go-dockerclient d750ee8aff39bca4ccf0b362db4f04510145d678
8 changes: 8 additions & 0 deletions docker-gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ type Event struct {
Image string `json:"from"`
}

type Network struct {
Name string
IP string
IP6LinkLocal string
IP6Global string
}

type Address struct {
IP string
IP6LinkLocal string
Expand All @@ -64,6 +71,7 @@ type Volume struct {
type RuntimeContainer struct {
ID string
Addresses []Address
Networks []Network
Gateway string
Name string
Hostname string
Expand Down
11 changes: 11 additions & 0 deletions docker_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func getContainers(client *docker.Client) ([]*RuntimeContainer, error) {
Hostname: container.Config.Hostname,
Gateway: container.NetworkSettings.Gateway,
Addresses: []Address{},
Networks: []Network{},
Env: make(map[string]string),
Volumes: make(map[string]Volume),
Node: SwarmNode{},
Expand Down Expand Up @@ -155,6 +156,16 @@ func getContainers(client *docker.Client) ([]*RuntimeContainer, error) {
ReadWrite: container.VolumesRW[k],
}
}
for k,v := range container.NetworkSettings.Networks {
fmt.Printf("", k)
network := Network{
Name: k,
IP: v.IPAddress,
}
runtimeContainer.Networks = append(runtimeContainer.Networks,
network)
}

if container.Node != nil {
runtimeContainer.Node.ID = container.Node.ID
runtimeContainer.Node.Name = container.Node.Name
Expand Down
9 changes: 9 additions & 0 deletions templates/nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ upstream {{ $host }} {
server {{ $address.IP }}:{{ $address.Port }};
{{ end }}

{{/* If a VIRTUAL_NETWORK is specified use use its IP */}}
{{ else if $value.Env.VIRTUAL_NETWORK }}
{{ range $i, $network := $value.Networks }}
{{ if eq $network.Name $value.Env.VIRTUAL_NETWORK }}
# Network: {{$network.Name}}
server {{ $network.IP }}:{{ $value.Env.VIRTUAL_PORT }};
{{ end }}
{{ end }}

{{/* If more than one port exposed, use the one matching VIRTUAL_PORT env var */}}
{{ else if $value.Env.VIRTUAL_PORT }}
{{ range $i, $address := $value.Addresses }}
Expand Down

6 comments on commit fdf2922

@bhurlow
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@schmunk42 this is working with docker compose?

@md5
Copy link
Contributor

@md5 md5 commented on fdf2922 Dec 20, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bhurlow This code is not merged. However, very similar code is part of #144, which will likely be merged soon.

@sergeyklay
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any plans about merging?

@schmunk42
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sergeyklay It's merged from here #144

@sergeyklay
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@schmunk42 This adds support of docker-compose v2 ?

@schmunk42
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See discussions in:

I haven't been able to try v2 on a swarm for myself, yet.

Please sign in to comment.