@@ -320,16 +320,25 @@ func getRestart(svc compose.ServiceConfig) (string, error) {
320
320
return restartFlag , nil
321
321
}
322
322
323
+ type networkNamePair struct {
324
+ shortNetworkName string
325
+ fullName string
326
+ }
327
+
323
328
// getNetworks returns full network names, e.g., {"compose-wordpress_default"}, or {"host"}
324
- func getNetworks (project * compose.Project , svc compose.ServiceConfig ) ([]string , error ) {
325
- var fullNames []string // nolint: prealloc
329
+ func getNetworks (project * compose.Project , svc compose.ServiceConfig ) ([]networkNamePair , error ) {
330
+ var fullNames []networkNamePair // nolint: prealloc
326
331
327
332
if svc .Net != "" {
328
333
logrus .Warn ("net is deprecated, use network_mode or networks" )
329
334
if len (svc .Networks ) > 0 {
330
335
return nil , errors .New ("networks and net must not be set together" )
331
336
}
332
- fullNames = append (fullNames , svc .Net )
337
+
338
+ fullNames = append (fullNames , networkNamePair {
339
+ fullName : svc .Net ,
340
+ shortNetworkName : "" ,
341
+ })
333
342
}
334
343
335
344
if svc .NetworkMode != "" {
@@ -342,15 +351,21 @@ func getNetworks(project *compose.Project, svc compose.ServiceConfig) ([]string,
342
351
if strings .Contains (svc .NetworkMode , ":" ) {
343
352
return nil , fmt .Errorf ("unsupported network_mode: %q" , svc .NetworkMode )
344
353
}
345
- fullNames = append (fullNames , svc .NetworkMode )
354
+ fullNames = append (fullNames , networkNamePair {
355
+ fullName : svc .NetworkMode ,
356
+ shortNetworkName : "" ,
357
+ })
346
358
}
347
359
348
360
for shortName := range svc .Networks {
349
361
net , ok := project .Networks [shortName ]
350
362
if ! ok {
351
363
return nil , fmt .Errorf ("invalid network %q" , shortName )
352
364
}
353
- fullNames = append (fullNames , net .Name )
365
+ fullNames = append (fullNames , networkNamePair {
366
+ fullName : net .Name ,
367
+ shortNetworkName : shortName ,
368
+ })
354
369
}
355
370
356
371
return fullNames , nil
@@ -514,7 +529,12 @@ func newContainer(project *compose.Project, parsed *Service, i int) (*Container,
514
529
return nil , err
515
530
} else {
516
531
for _ , net := range networks {
517
- c .RunArgs = append (c .RunArgs , "--net=" + net )
532
+ c .RunArgs = append (c .RunArgs , "--net=" + net .fullName )
533
+ if value , ok := svc .Networks [net .shortNetworkName ]; ok {
534
+ if value != nil && value .Ipv4Address != "" {
535
+ c .RunArgs = append (c .RunArgs , "--ip=" + value .Ipv4Address )
536
+ }
537
+ }
518
538
}
519
539
}
520
540
0 commit comments