github.com/wozhu6104/docker@v20.10.10+incompatible/daemon/container_unix_test.go (about) 1 // +build linux freebsd 2 3 package daemon 4 5 import ( 6 "testing" 7 8 "github.com/docker/docker/api/types" 9 containertypes "github.com/docker/docker/api/types/container" 10 "github.com/docker/docker/daemon/config" 11 "github.com/docker/go-connections/nat" 12 "gotest.tools/v3/assert" 13 ) 14 15 // TestContainerWarningHostAndPublishPorts that a warning is returned when setting network mode to host and specifying published ports. 16 // This should not be tested on Windows because Windows doesn't support "host" network mode. 17 func TestContainerWarningHostAndPublishPorts(t *testing.T) { 18 testCases := []struct { 19 ports nat.PortMap 20 warnings []string 21 }{ 22 {ports: nat.PortMap{}}, 23 {ports: nat.PortMap{ 24 "8080": []nat.PortBinding{{HostPort: "8989"}}, 25 }, warnings: []string{"Published ports are discarded when using host network mode"}}, 26 } 27 muteLogs() 28 29 for _, tc := range testCases { 30 hostConfig := &containertypes.HostConfig{ 31 Runtime: "runc", 32 NetworkMode: "host", 33 PortBindings: tc.ports, 34 } 35 cs := &config.Config{ 36 CommonUnixConfig: config.CommonUnixConfig{ 37 Runtimes: map[string]types.Runtime{"runc": {}}, 38 }, 39 } 40 d := &Daemon{configStore: cs} 41 wrns, err := d.verifyContainerSettings("", hostConfig, &containertypes.Config{}, false) 42 assert.NilError(t, err) 43 assert.DeepEqual(t, tc.warnings, wrns) 44 } 45 }