@@ -477,12 +477,7 @@ func (d *LocalRunner) applyTemplate(s *Service) ([]string, map[string]string, er
477
477
}
478
478
479
479
funcs := template.FuncMap {
480
- "Service" : func (name string , portLabel , protocol string ) string {
481
- protocolPrefix := ""
482
- if protocol == "http" {
483
- protocolPrefix = "http://"
484
- }
485
-
480
+ "Service" : func (name string , portLabel , protocol , user string ) string {
486
481
// For {{Service "name" "portLabel"}}:
487
482
// - Service runs on host:
488
483
// A: target is inside docker: access with localhost:hostPort
@@ -497,14 +492,14 @@ func (d *LocalRunner) applyTemplate(s *Service) ([]string, map[string]string, er
497
492
498
493
if d .isHostService (s .Name ) {
499
494
// A and B
500
- return fmt . Sprintf ( "%slocalhost:%d " , protocolPrefix , port .HostPort )
495
+ return printAddr ( protocol , "localhost " , port .HostPort , user )
501
496
} else {
502
497
if d .isHostService (svc .Name ) {
503
498
// D
504
- return fmt . Sprintf ( "%shost .docker.internal:%d " , protocolPrefix , port .HostPort )
499
+ return printAddr ( protocol , "host .docker.internal" , port .HostPort , user )
505
500
}
506
501
// C
507
- return fmt . Sprintf ( "%s%s:%d" , protocolPrefix , svc .Name , port .Port )
502
+ return printAddr ( protocol , svc .Name , port .Port , user )
508
503
}
509
504
},
510
505
"Port" : func (name string , defaultPort int ) int {
@@ -552,6 +547,19 @@ func (d *LocalRunner) applyTemplate(s *Service) ([]string, map[string]string, er
552
547
return argsResult , envs , nil
553
548
}
554
549
550
+ func printAddr (protocol , serviceName string , port int , user string ) string {
551
+ var protocolPrefix string
552
+ if protocol != "" {
553
+ protocolPrefix = protocol + "://"
554
+ }
555
+
556
+ if user != "" {
557
+ return fmt .Sprintf ("%s%s@%s:%s" , protocolPrefix , user , serviceName , serviceName )
558
+ }
559
+
560
+ return fmt .Sprintf ("%s%s:%d" , protocolPrefix , serviceName , port )
561
+ }
562
+
555
563
func (d * LocalRunner ) validateImageExists (image string ) error {
556
564
// check locally
557
565
_ , err := d .client .ImageInspect (context .Background (), image )
@@ -570,7 +578,7 @@ func (d *LocalRunner) validateImageExists(image string) error {
570
578
return err
571
579
}
572
580
573
- return fmt .Errorf ("image %s not found: %w " , image )
581
+ return fmt .Errorf ("image %s not found" , image )
574
582
}
575
583
576
584
func (d * LocalRunner ) toDockerComposeService (s * Service ) (map [string ]interface {}, error ) {
0 commit comments