@@ -131,8 +131,8 @@ DockerModule.prototype.register = function (src, target, opts) {
131
131
132
132
DockerModule . prototype . registerContainer = function ( src , containerId , opts ) {
133
133
var _this = this ;
134
- containerPort ( this . dolphin , containerId ) . then ( function ( targetPort ) {
135
- _this . redbird . register ( src , targetPort , opts ) ;
134
+ containerPort ( this . dolphin , containerId , opts ) . then ( function ( targetPort ) {
135
+ _this . redbird . register ( src , targetPort + ( opts . container && opts . container . path ? '/' + opts . container . path : '' ) , opts ) ;
136
136
_this . ports [ containerId ] = targetPort ;
137
137
} ) ;
138
138
} ;
@@ -142,18 +142,26 @@ function isMatchingImageName(targetName, imageName) {
142
142
return regex . test ( imageName ) ;
143
143
}
144
144
145
- function containerPort ( dolphin , containerId ) {
145
+ function containerPort ( dolphin , containerId , opts ) {
146
146
return dolphin . containers . inspect ( containerId ) . then ( function ( container ) {
147
147
var port = Object . keys ( container . NetworkSettings . Ports ) [ 0 ] . split ( '/' ) [ 0 ] ;
148
+ if ( opts . container && opts . container . port && container . NetworkSettings . Ports . hasOwnProperty ( [ opts . container . port + '/tcp' ] ) ) {
149
+ port = opts . container . port ;
150
+ }
148
151
149
- var netNames = Object . keys ( container . NetworkSettings . Networks ) ;
152
+ var ip , netNames = Object . keys ( container . NetworkSettings . Networks ) ;
150
153
if ( netNames . length === 1 ) {
151
- var ip = container . NetworkSettings . Networks [ netNames [ 0 ] ] . IPAddress ;
154
+ ip = container . NetworkSettings . Networks [ netNames [ 0 ] ] . IPAddress ;
152
155
if ( port && ip ) {
153
156
return 'http://' + ip + ':' + port ;
154
157
}
155
158
} else {
156
- //TODO: Implements opts for manually choosing the network/ip/port...
159
+ if ( opts . container && opts . container . network && container . NetworkSettings . Networks [ opts . container . network ] ) {
160
+ ip = container . NetworkSettings . Networks [ opts . container . network ] . IPAddress ;
161
+ if ( port && ip ) {
162
+ return 'http://' + ip + ':' + port ;
163
+ }
164
+ }
157
165
}
158
166
throw Error ( 'No valid address or port ' + container . IPAddress + ':' + port ) ;
159
167
} ) ;
0 commit comments