Browse code

Expose IP, port, proto as sep. env vars when linking, Closes #2430

Scott Bessler authored on 2013/10/29 15:02:28
Showing 4 changed files
... ...
@@ -151,6 +151,7 @@ Roberto Hashioka <roberto_hashioka@hotmail.com>
151 151
 Ryan Fowler <rwfowler@gmail.com>
152 152
 Sam Alba <sam.alba@gmail.com>
153 153
 Sam J Sharpe <sam.sharpe@digital.cabinet-office.gov.uk>
154
+Scott Bessler <scottbessler@gmail.com>
154 155
 Sean P. Kane <skane@newrelic.com>
155 156
 Shawn Siefkas <shawn.siefkas@meredith.com>
156 157
 Shih-Yuan Lee <fourdollars@gmail.com>
... ...
@@ -87,6 +87,9 @@ Now lets start our web application with a link into redis.
87 87
     TERM=xterm
88 88
     DB_PORT=tcp://172.17.0.8:6379
89 89
     DB_PORT_6379_TCP=tcp://172.17.0.8:6379
90
+    DB_PORT_6379_TCP_PROTO=tcp
91
+    DB_PORT_6379_TCP_ADDR=172.17.0.8
92
+    DB_PORT_6379_TCP_PORT=6379
90 93
     PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
91 94
     PWD=/
92 95
     DB_ENV_PASSWORD=dockerpass
... ...
@@ -111,6 +114,9 @@ network and environment information from the child.
111 111
     DB_PORT=tcp://172.17.0.8:6379
112 112
     # A specific protocol, ip, and port of various services
113 113
     DB_PORT_6379_TCP=tcp://172.17.0.8:6379
114
+    DB_PORT_6379_TCP_PROTO=tcp
115
+    DB_PORT_6379_TCP_ADDR=172.17.0.8
116
+    DB_PORT_6379_TCP_PORT=6379
114 117
     # Get environment variables of the container 
115 118
     DB_ENV_PASSWORD=dockerpass
116 119
 
... ...
@@ -60,6 +60,9 @@ func (l *Link) ToEnv() []string {
60 60
 	// Load exposed ports into the environment
61 61
 	for _, p := range l.Ports {
62 62
 		env = append(env, fmt.Sprintf("%s_PORT_%s_%s=%s://%s:%s", alias, p.Port(), strings.ToUpper(p.Proto()), p.Proto(), l.ChildIP, p.Port()))
63
+		env = append(env, fmt.Sprintf("%s_PORT_%s_%s_ADDR=%s", alias, p.Port(), strings.ToUpper(p.Proto()), l.ChildIP))
64
+		env = append(env, fmt.Sprintf("%s_PORT_%s_%s_PORT=%s", alias, p.Port(), strings.ToUpper(p.Proto()), p.Port()))
65
+		env = append(env, fmt.Sprintf("%s_PORT_%s_%s_PROTO=%s", alias, p.Port(), strings.ToUpper(p.Proto()), p.Proto()))
63 66
 	}
64 67
 
65 68
 	// Load the linked container's name into the environment
... ...
@@ -95,6 +95,15 @@ func TestLinkEnv(t *testing.T) {
95 95
 	if env["DOCKER_PORT_6379_TCP"] != "tcp://172.0.17.2:6379" {
96 96
 		t.Fatalf("Expected tcp://172.0.17.2:6379, got %s", env["DOCKER_PORT_6379_TCP"])
97 97
 	}
98
+	if env["DOCKER_PORT_6379_TCP_PROTO"] != "tcp" {
99
+		t.Fatalf("Expected tcp, got %s", env["DOCKER_PORT_6379_TCP_PROTO"])
100
+	}
101
+	if env["DOCKER_PORT_6379_TCP_ADDR"] != "172.0.17.2" {
102
+		t.Fatalf("Expected 172.0.17.2, got %s", env["DOCKER_PORT_6379_TCP_ADDR"])
103
+	}
104
+	if env["DOCKER_PORT_6379_TCP_PORT"] != "6379" {
105
+		t.Fatalf("Expected 6379, got %s", env["DOCKER_PORT_6379_TCP_PORT"])
106
+	}
98 107
 	if env["DOCKER_NAME"] != "/db/docker" {
99 108
 		t.Fatalf("Expected /db/docker, got %s", env["DOCKER_NAME"])
100 109
 	}