@@ -59,6 +59,9 @@ type LocalRunner struct {
59
59
tasksMtx sync.Mutex
60
60
tasks map [string ]* task
61
61
taskUpdateCh chan struct {}
62
+
63
+ // wether to bind the ports to the local interface
64
+ bindHostPortsLocally bool
62
65
}
63
66
64
67
type task struct {
@@ -88,12 +91,14 @@ func newDockerClient() (*client.Client, error) {
88
91
return client , nil
89
92
}
90
93
91
- func NewLocalRunner (out * output , manifest * Manifest , overrides map [string ]string , interactive bool ) (* LocalRunner , error ) {
94
+ func NewLocalRunner (out * output , manifest * Manifest , overrides map [string ]string , interactive bool , bindHostPortsLocally bool ) (* LocalRunner , error ) {
92
95
client , err := newDockerClient ()
93
96
if err != nil {
94
97
return nil , fmt .Errorf ("failed to create docker client: %w" , err )
95
98
}
96
99
100
+ fmt .Println (bindHostPortsLocally )
101
+
97
102
// merge the overrides with the manifest overrides
98
103
if overrides == nil {
99
104
overrides = make (map [string ]string )
@@ -134,15 +139,16 @@ func NewLocalRunner(out *output, manifest *Manifest, overrides map[string]string
134
139
}
135
140
136
141
d := & LocalRunner {
137
- out : out ,
138
- manifest : manifest ,
139
- client : client ,
140
- reservedPorts : map [int ]bool {},
141
- overrides : overrides ,
142
- handles : []* exec.Cmd {},
143
- tasks : tasks ,
144
- taskUpdateCh : make (chan struct {}),
145
- exitErr : make (chan error , 2 ),
142
+ out : out ,
143
+ manifest : manifest ,
144
+ client : client ,
145
+ reservedPorts : map [int ]bool {},
146
+ overrides : overrides ,
147
+ handles : []* exec.Cmd {},
148
+ tasks : tasks ,
149
+ taskUpdateCh : make (chan struct {}),
150
+ exitErr : make (chan error , 2 ),
151
+ bindHostPortsLocally : bindHostPortsLocally ,
146
152
}
147
153
148
154
if interactive {
@@ -580,10 +586,18 @@ func (d *LocalRunner) toDockerComposeService(s *service) (map[string]interface{}
580
586
service ["entrypoint" ] = s .entrypoint
581
587
}
582
588
589
+ fmt .Println ("XXX" )
590
+
583
591
if len (s .ports ) > 0 {
584
592
ports := []string {}
593
+ fmt .Println ("x" , d .bindHostPortsLocally )
594
+
585
595
for _ , p := range s .ports {
586
- ports = append (ports , fmt .Sprintf ("%d:%d" , p .HostPort , p .Port ))
596
+ if d .bindHostPortsLocally {
597
+ ports = append (ports , fmt .Sprintf ("127.0.0.1:%d:%d" , p .HostPort , p .Port ))
598
+ } else {
599
+ ports = append (ports , fmt .Sprintf ("%d:%d" , p .HostPort , p .Port ))
600
+ }
587
601
}
588
602
service ["ports" ] = ports
589
603
}
0 commit comments