@@ -559,6 +559,80 @@ func TestFirewalldReloadNoZombies(t *testing.T) {
559559 "After deletes: did not expect rules for %s in: %s" , bridgeName , resAfterReload .Combined ())
560560}
561561
562+ // TestLegacyLink checks that a legacy link ("--link" in the default bridge network)
563+ // sets up a hostname and opens ports when the daemon is running with icc=false.
564+ func TestLegacyLink (t * testing.T ) {
565+ ctx := setupTest (t )
566+
567+ // Tidy up after the test by starting a new daemon, which will remove the icc=false
568+ // rules this test will create for docker0.
569+ defer func () {
570+ d := daemon .New (t )
571+ d .StartWithBusybox (ctx , t )
572+ defer d .Stop (t )
573+ }()
574+
575+ d := daemon .New (t )
576+ d .StartWithBusybox (ctx , t , "--icc=false" )
577+ defer d .Stop (t )
578+ c := d .NewClientT (t )
579+
580+ // Run an http server.
581+ const svrName = "svr"
582+ cid := ctr .Run (ctx , t , c ,
583+ ctr .WithExposedPorts ("80/tcp" ),
584+ ctr .WithName (svrName ),
585+ ctr .WithCmd ("httpd" , "-f" ),
586+ )
587+
588+ defer ctr .Remove (ctx , t , c , cid , containertypes.RemoveOptions {Force : true })
589+ insp := ctr .Inspect (ctx , t , c , cid )
590+ svrAddr := insp .NetworkSettings .Networks ["bridge" ].IPAddress
591+
592+ const svrAlias = "thealias"
593+ testcases := []struct {
594+ name string
595+ host string
596+ links []string
597+ expect string
598+ }{
599+ {
600+ name : "no link" ,
601+ host : svrAddr ,
602+ expect : "download timed out" ,
603+ },
604+ {
605+ name : "access by address" ,
606+ links : []string {svrName },
607+ host : svrAddr ,
608+ expect : "404 Not Found" , // Got a response, but the server has nothing to serve.
609+ },
610+ {
611+ name : "access by name" ,
612+ links : []string {svrName },
613+ host : svrName ,
614+ expect : "404 Not Found" , // Got a response, but the server has nothing to serve.
615+ },
616+ {
617+ name : "access by alias" ,
618+ links : []string {svrName + ":" + svrAlias },
619+ host : svrAlias ,
620+ expect : "404 Not Found" , // Got a response, but the server has nothing to serve.
621+ },
622+ }
623+
624+ for _ , tc := range testcases {
625+ t .Run (tc .name , func (t * testing.T ) {
626+ ctx := testutil .StartSpan (ctx , t )
627+ res := ctr .RunAttach (ctx , t , c ,
628+ ctr .WithLinks (tc .links ... ),
629+ ctr .WithCmd ("wget" , "-T3" , "http://" + tc .host ),
630+ )
631+ assert .Check (t , is .Contains (res .Stderr .String (), tc .expect ))
632+ })
633+ }
634+ }
635+
562636// TestRemoveLegacyLink checks that a legacy link can be deleted while the
563637// linked containers are running.
564638//
0 commit comments