fix(docker): declare no exposed port for a container in a namespace network mode (#8237)

* fix(docker): declare no exposed port for a container in a namespace network mode
This commit is contained in:
Charles Swanberg authored and GitHub committed 2026-11-21 13:34:09 -04:00
1 parent 6e6d4eaf53
commit f7828d50b9
2 files changed
+40 -1

No files matched your search

@@ -376,7 +376,12 @@ public class ContainerLifecycleManager {
if (spec.workingDir() != null && !spec.workingDir().isBlank()) {
createCmd.withWorkingDir(spec.workingDir());
}
if (spec.exposedPorts() != null && !spec.exposedPorts().isEmpty()) {
// A container sharing a network namespace (host, none, container:<id>) has no endpoint
// of its own for Docker to expose a port on, and the daemon refuses an exposed port
// together with container:<id> ("conflicting options: port exposing and the container
// type network mode"). The spec keeps the ports: resolveEndpoints still answers them
// through the namespace's owner.
if (spec.exposedPorts() != null && !spec.exposedPorts().isEmpty() && !spec.sharesNetworkNamespace()) {
ExposedPort[] exposed = spec.exposedPorts().stream()
.map(ExposedPort::tcp)
.toArray(ExposedPort[]::new);