@@ -437,3 +437,56 @@ services:
437
437
base .ComposeCmd ("-f" , comp .YAMLFullPath (), "down" ).AssertOK ()
438
438
439
439
}
440
+
441
+ func TestComposeUpWithExternalNetwork (t * testing.T ) {
442
+ containerName1 := testutil .Identifier (t ) + "-1"
443
+ containerName2 := testutil .Identifier (t ) + "-2"
444
+ networkName := testutil .Identifier (t ) + "-network"
445
+ var dockerComposeYaml1 = fmt .Sprintf (`
446
+ version: "3"
447
+ services:
448
+ %s:
449
+ image: %s
450
+ container_name: %s
451
+ networks:
452
+ %s:
453
+ aliases:
454
+ - nginx-1
455
+ networks:
456
+ %s:
457
+ external: true
458
+ ` , containerName1 , testutil .NginxAlpineImage , containerName1 , networkName , networkName )
459
+ var dockerComposeYaml2 = fmt .Sprintf (`
460
+ version: "3"
461
+ services:
462
+ %s:
463
+ image: %s
464
+ container_name: %s
465
+ networks:
466
+ %s:
467
+ aliases:
468
+ - nginx-2
469
+ networks:
470
+ %s:
471
+ external: true
472
+ ` , containerName2 , testutil .NginxAlpineImage , containerName2 , networkName , networkName )
473
+ comp1 := testutil .NewComposeDir (t , dockerComposeYaml1 )
474
+ defer comp1 .CleanUp ()
475
+ comp2 := testutil .NewComposeDir (t , dockerComposeYaml2 )
476
+ defer comp2 .CleanUp ()
477
+ base := testutil .NewBase (t )
478
+ // Create the test network
479
+ base .Cmd ("network" , "create" , networkName ).AssertOK ()
480
+ defer base .Cmd ("network" , "rm" , networkName ).Run ()
481
+ // Run the first compose
482
+ base .ComposeCmd ("-f" , comp1 .YAMLFullPath (), "up" , "-d" ).AssertOK ()
483
+ defer base .ComposeCmd ("-f" , comp1 .YAMLFullPath (), "down" , "-v" ).Run ()
484
+ // Run the second compose
485
+ base .ComposeCmd ("-f" , comp2 .YAMLFullPath (), "up" , "-d" ).AssertOK ()
486
+ defer base .ComposeCmd ("-f" , comp2 .YAMLFullPath (), "down" , "-v" ).Run ()
487
+ // Down the second compose
488
+ base .ComposeCmd ("-f" , comp2 .YAMLFullPath (), "down" , "-v" ).AssertOK ()
489
+ // Run the second compose again
490
+ base .ComposeCmd ("-f" , comp2 .YAMLFullPath (), "up" , "-d" ).AssertOK ()
491
+ base .Cmd ("exec" , containerName1 , "wget" , "-qO-" , "http://" + containerName2 ).AssertOutContains (testutil .NginxAlpineIndexHTMLSnippet )
492
+ }
0 commit comments