@@ -477,12 +477,7 @@ func (d *LocalRunner) applyTemplate(s *Service) ([]string, map[string]string, er
477477 }
478478
479479 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 {
486481 // For {{Service "name" "portLabel"}}:
487482 // - Service runs on host:
488483 // A: target is inside docker: access with localhost:hostPort
@@ -497,14 +492,14 @@ func (d *LocalRunner) applyTemplate(s *Service) ([]string, map[string]string, er
497492
498493 if d .isHostService (s .Name ) {
499494 // A and B
500- return fmt . Sprintf ( "%slocalhost:%d " , protocolPrefix , port .HostPort )
495+ return printAddr ( protocol , "localhost " , port .HostPort , user )
501496 } else {
502497 if d .isHostService (svc .Name ) {
503498 // D
504- return fmt . Sprintf ( "%shost .docker.internal:%d " , protocolPrefix , port .HostPort )
499+ return printAddr ( protocol , "host .docker.internal" , port .HostPort , user )
505500 }
506501 // C
507- return fmt . Sprintf ( "%s%s:%d" , protocolPrefix , svc .Name , port .Port )
502+ return printAddr ( protocol , svc .Name , port .Port , user )
508503 }
509504 },
510505 "Port" : func (name string , defaultPort int ) int {
@@ -552,6 +547,19 @@ func (d *LocalRunner) applyTemplate(s *Service) ([]string, map[string]string, er
552547 return argsResult , envs , nil
553548}
554549
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+
555563func (d * LocalRunner ) validateImageExists (image string ) error {
556564 // check locally
557565 _ , err := d .client .ImageInspect (context .Background (), image )
@@ -570,7 +578,7 @@ func (d *LocalRunner) validateImageExists(image string) error {
570578 return err
571579 }
572580
573- return fmt .Errorf ("image %s not found: %w " , image )
581+ return fmt .Errorf ("image %s not found" , image )
574582}
575583
576584func (d * LocalRunner ) toDockerComposeService (s * Service ) (map [string ]interface {}, error ) {
0 commit comments