Skip to content

Commit 7aaca57

Browse files
committed
Add Gateway and HostPort to meta-data
Useful when running docker-gen within a container to generate reverse proxy configs.
1 parent 81293bc commit 7aaca57

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

docker-gen.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ type Event struct {
3232
}
3333

3434
type Address struct {
35-
IP string
36-
Port string
35+
IP string
36+
Port string
37+
HostPort string
3738
}
3839
type RuntimeContainer struct {
3940
ID string
4041
Addresses []Address
42+
Gateway string
4143
Image DockerImage
4244
Env map[string]string
4345
}

docker_client.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,21 @@ func getContainers(client *docker.Client) ([]*RuntimeContainer, error) {
202202
Repository: repository,
203203
Tag: tag,
204204
},
205+
Gateway: container.NetworkSettings.Gateway,
205206
Addresses: []Address{},
206207
Env: make(map[string]string),
207208
}
208-
for k, _ := range container.NetworkSettings.Ports {
209+
for k, v := range container.NetworkSettings.Ports {
210+
address := Address{
211+
IP: container.NetworkSettings.IPAddress,
212+
Port: k.Port(),
213+
}
214+
if len(v) > 0 {
215+
address.HostPort = v[0].HostPort
216+
}
209217
runtimeContainer.Addresses = append(runtimeContainer.Addresses,
210-
Address{
211-
IP: container.NetworkSettings.IPAddress,
212-
Port: k.Port(),
213-
})
218+
address)
219+
214220
}
215221

216222
for _, entry := range container.Config.Env {

0 commit comments

Comments
 (0)