@@ -163,25 +163,33 @@ func (d *Daemon) OnContainerStart(ctx context.Context, info watcher.ContainerInf
163163 continue
164164 }
165165
166+ newPortMappings = append (newPortMappings , state.PortMapping {
167+ ContainerPort : e .containerPort ,
168+ HostPort : e .hostPort ,
169+ Service : e .service ,
170+ })
171+
172+ // When host port == container port, Docker's 0.0.0.0 binding already
173+ // covers the project loopback IP. No forwarder needed — DNS alone is enough.
174+ if e .hostPort == e .containerPort {
175+ slog .Info ("direct access via Docker binding (host==container port)" ,
176+ "project" , project , "service" , e .service , "port" , e .containerPort )
177+ continue
178+ }
179+
166180 targetAddr := fmt .Sprintf ("127.0.0.1:%d" , e .hostPort )
167181
168182 fwdCtx , fwdCancel := context .WithCancel (ctx )
169183 fwd := forwarder .New (listenAddr , targetAddr )
170184 go func () {
171185 if err := fwd .Start (fwdCtx ); err != nil {
172- slog .Error ("forwarder error " , "listen" , listenAddr , "error" , err )
186+ slog .Warn ("forwarder bind failed " , "listen" , listenAddr , "error" , err )
173187 }
174188 }()
175189
176190 d .forwarders [project ] = append (d .forwarders [project ], fwd )
177191 d .cancelFns [cancelKey ] = fwdCancel
178192
179- newPortMappings = append (newPortMappings , state.PortMapping {
180- ContainerPort : e .containerPort ,
181- HostPort : e .hostPort ,
182- Service : e .service ,
183- })
184-
185193 slog .Info ("forwarding" , "project" , project , "listen" , listenAddr , "target" , targetAddr )
186194 }
187195
0 commit comments