2018-05-11 15:46:11 -04:00
|
|
|
package container // import "github.com/docker/docker/integration/container"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
containertypes "github.com/docker/docker/api/types/container"
|
2018-10-27 13:44:52 -04:00
|
|
|
"github.com/docker/docker/api/types/versions"
|
2018-05-11 15:46:11 -04:00
|
|
|
"github.com/docker/docker/integration/internal/container"
|
2019-05-11 09:09:42 -04:00
|
|
|
net "github.com/docker/docker/integration/internal/network"
|
2020-02-07 08:39:24 -05:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
is "gotest.tools/v3/assert/cmp"
|
|
|
|
"gotest.tools/v3/poll"
|
|
|
|
"gotest.tools/v3/skip"
|
2018-05-11 15:46:11 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestKernelTCPMemory(t *testing.T) {
|
|
|
|
skip.If(t, testEnv.DaemonInfo.OSType != "linux")
|
2018-10-27 13:44:52 -04:00
|
|
|
skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.40"), "skip test from new feature")
|
2020-02-18 04:43:56 -05:00
|
|
|
skip.If(t, testEnv.DaemonInfo.CgroupDriver == "none")
|
2018-05-11 15:46:11 -04:00
|
|
|
skip.If(t, !testEnv.DaemonInfo.KernelMemoryTCP)
|
|
|
|
|
|
|
|
defer setupTest(t)()
|
2019-01-02 08:16:25 -05:00
|
|
|
client := testEnv.APIClient()
|
2018-05-11 15:46:11 -04:00
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
const (
|
|
|
|
kernelMemoryTCP int64 = 200 * 1024 * 1024
|
|
|
|
)
|
|
|
|
|
2019-06-06 07:15:31 -04:00
|
|
|
cID := container.Run(ctx, t, client, func(c *container.TestContainerConfig) {
|
2018-05-11 15:46:11 -04:00
|
|
|
c.HostConfig.Resources = containertypes.Resources{
|
|
|
|
KernelMemoryTCP: kernelMemoryTCP,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond))
|
|
|
|
|
|
|
|
inspect, err := client.ContainerInspect(ctx, cID)
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Equal(kernelMemoryTCP, inspect.HostConfig.KernelMemoryTCP))
|
|
|
|
|
|
|
|
res, err := container.Exec(ctx, client, cID,
|
|
|
|
[]string{"cat", "/sys/fs/cgroup/memory/memory.kmem.tcp.limit_in_bytes"})
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Assert(t, is.Len(res.Stderr(), 0))
|
|
|
|
assert.Equal(t, 0, res.ExitCode)
|
|
|
|
assert.Check(t, is.Equal(strconv.FormatInt(kernelMemoryTCP, 10), strings.TrimSpace(res.Stdout())))
|
|
|
|
}
|
2018-11-30 01:31:44 -05:00
|
|
|
|
|
|
|
func TestNISDomainname(t *testing.T) {
|
2019-04-19 12:51:33 -04:00
|
|
|
// Older versions of the daemon would concatenate hostname and domainname,
|
|
|
|
// so hostname "foobar" and domainname "baz.cyphar.com" would produce
|
|
|
|
// `foobar.baz.cyphar.com` as hostname.
|
|
|
|
skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.40"), "skip test from new feature")
|
2018-11-30 01:31:44 -05:00
|
|
|
skip.If(t, testEnv.DaemonInfo.OSType != "linux")
|
|
|
|
|
2020-02-18 04:43:56 -05:00
|
|
|
// Rootless supports custom Hostname but doesn't support custom Domainname
|
|
|
|
// OCI runtime create failed: container_linux.go:349: starting container process caused "process_linux.go:449: container init caused \
|
|
|
|
// "write sysctl key kernel.domainname: open /proc/sys/kernel/domainname: permission denied\"": unknown.
|
|
|
|
skip.If(t, testEnv.IsRootless, "rootless mode doesn't support setting Domainname (TODO: https://github.com/moby/moby/issues/40632)")
|
|
|
|
|
2018-11-30 01:31:44 -05:00
|
|
|
defer setupTest(t)()
|
2019-01-02 08:16:25 -05:00
|
|
|
client := testEnv.APIClient()
|
2018-11-30 01:31:44 -05:00
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
const (
|
|
|
|
hostname = "foobar"
|
|
|
|
domainname = "baz.cyphar.com"
|
|
|
|
)
|
|
|
|
|
2019-06-06 07:15:31 -04:00
|
|
|
cID := container.Run(ctx, t, client, func(c *container.TestContainerConfig) {
|
2018-11-30 01:31:44 -05:00
|
|
|
c.Config.Hostname = hostname
|
|
|
|
c.Config.Domainname = domainname
|
|
|
|
})
|
|
|
|
|
|
|
|
poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond))
|
|
|
|
|
|
|
|
inspect, err := client.ContainerInspect(ctx, cID)
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Equal(hostname, inspect.Config.Hostname))
|
|
|
|
assert.Check(t, is.Equal(domainname, inspect.Config.Domainname))
|
|
|
|
|
|
|
|
// Check hostname.
|
|
|
|
res, err := container.Exec(ctx, client, cID,
|
|
|
|
[]string{"cat", "/proc/sys/kernel/hostname"})
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Assert(t, is.Len(res.Stderr(), 0))
|
|
|
|
assert.Equal(t, 0, res.ExitCode)
|
|
|
|
assert.Check(t, is.Equal(hostname, strings.TrimSpace(res.Stdout())))
|
|
|
|
|
|
|
|
// Check domainname.
|
|
|
|
res, err = container.Exec(ctx, client, cID,
|
|
|
|
[]string{"cat", "/proc/sys/kernel/domainname"})
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Assert(t, is.Len(res.Stderr(), 0))
|
|
|
|
assert.Equal(t, 0, res.ExitCode)
|
|
|
|
assert.Check(t, is.Equal(domainname, strings.TrimSpace(res.Stdout())))
|
|
|
|
}
|
2019-05-11 09:09:42 -04:00
|
|
|
|
|
|
|
func TestHostnameDnsResolution(t *testing.T) {
|
|
|
|
skip.If(t, testEnv.DaemonInfo.OSType != "linux")
|
|
|
|
|
|
|
|
defer setupTest(t)()
|
|
|
|
client := testEnv.APIClient()
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
const (
|
|
|
|
hostname = "foobar"
|
|
|
|
)
|
|
|
|
|
|
|
|
// using user defined network as we want to use internal DNS
|
|
|
|
netName := "foobar-net"
|
2019-06-06 06:00:19 -04:00
|
|
|
net.CreateNoError(context.Background(), t, client, netName, net.WithDriver("bridge"))
|
2019-05-11 09:09:42 -04:00
|
|
|
|
2019-06-06 07:15:31 -04:00
|
|
|
cID := container.Run(ctx, t, client, func(c *container.TestContainerConfig) {
|
2019-05-11 09:09:42 -04:00
|
|
|
c.Config.Hostname = hostname
|
|
|
|
c.HostConfig.NetworkMode = containertypes.NetworkMode(netName)
|
|
|
|
})
|
|
|
|
|
|
|
|
poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond))
|
|
|
|
|
|
|
|
inspect, err := client.ContainerInspect(ctx, cID)
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Equal(hostname, inspect.Config.Hostname))
|
|
|
|
|
|
|
|
// Clear hosts file so ping will use DNS for hostname resolution
|
|
|
|
res, err := container.Exec(ctx, client, cID,
|
|
|
|
[]string{"sh", "-c", "echo 127.0.0.1 localhost | tee /etc/hosts && ping -c 1 foobar"})
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Equal("", res.Stderr()))
|
|
|
|
assert.Equal(t, 0, res.ExitCode)
|
|
|
|
}
|