Skip to content

Commit 9f1141b

Browse files
fuchiaoarekkas
authored andcommitted
Add network option (#137)
Signed-off-by: Chang Fu Chiao <[email protected]>
1 parent bb9a1e0 commit 9f1141b

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

dockertest.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ type RunOptions struct {
173173
CapAdd []string
174174
SecurityOpt []string
175175
WorkingDir string
176+
NetworkID string
176177
Labels map[string]string
177178
Auth dc.AuthConfiguration
178179
PortBindings map[dc.Port][]dc.PortBinding
@@ -243,6 +244,13 @@ func (d *Pool) RunWithOptions(opts *RunOptions) (*Resource, error) {
243244
tag = "latest"
244245
}
245246

247+
networkingConfig := dc.NetworkingConfig{
248+
EndpointsConfig: map[string]*dc.EndpointConfig{},
249+
}
250+
if opts.NetworkID != "" {
251+
networkingConfig.EndpointsConfig[opts.NetworkID] = &dc.EndpointConfig{}
252+
}
253+
246254
_, err := d.Client.InspectImage(fmt.Sprintf("%s:%s", repository, tag))
247255
if err != nil {
248256
if err := d.Client.PullImage(dc.PullImageOptions{
@@ -277,6 +285,7 @@ func (d *Pool) RunWithOptions(opts *RunOptions) (*Resource, error) {
277285
SecurityOpt: opts.SecurityOpt,
278286
Privileged: opts.Privileged,
279287
},
288+
NetworkingConfig: &networkingConfig,
280289
})
281290
if err != nil {
282291
return nil, errors.Wrap(err, "")

0 commit comments

Comments
 (0)