Skip to content

Commit 17ece6e

Browse files
committed
fix(docker): correctly validate container network mode
The previous implementation of `IsContainerNetworkMode` considered `container:` an empty but valid container network mode. However, Docker rejects "container:" without a name with "invalid container format container:". This commit updates the `IsContainerNetworkMode` function to ensure that there is at least one character for the container name after "container:", aligning the validation with Docker's behavior.
1 parent 1b335de commit 17ece6e

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

config/config_docker.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ type DockerNetworkConfiguration struct {
4747
// When using "container:<name>" mode, the container inherits the target container's network stack,
4848
// including hostname, DNS, and network interfaces.
4949
func (c DockerNetworkConfiguration) IsContainerNetworkMode() bool {
50-
return strings.HasPrefix(c.Mode, "container:")
50+
// Must have "container:" prefix and at least one character for the container name.
51+
// Docker rejects "container:" without a name with "invalid container format container:".
52+
return strings.HasPrefix(c.Mode, "container:") && len(c.Mode) > len("container:")
5153
}
5254

5355
// DockerConfiguration defines the docker configuration used by the daemon when

config/config_docker_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func TestDockerNetworkConfiguration_IsContainerNetworkMode(t *testing.T) {
1313
}{
1414
{"container mode with name", "container:caddy", true},
1515
{"container mode with different name", "container:some-vpn-container", true},
16-
{"container mode empty name", "container:", true}, // Edge case: technically valid prefix
16+
{"container mode empty name", "container:", false}, // Docker rejects "container:" without a name
1717
{"default pelican network", "pelican_nw", false},
1818
{"bridge network", "bridge", false},
1919
{"host network", "host", false},

0 commit comments

Comments
 (0)