mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
Merge pull request #51507 from zhangguanzhang/fix-pause-restart
libnet: setupDNS: don't overwrite user-modified resolv.conf
This commit is contained in:
@@ -212,3 +212,41 @@ func TestNslookupWindows(t *testing.T) {
|
||||
// can only be changed in daemon.json using feature flag "windows-dns-proxy".
|
||||
assert.Check(t, is.Contains(res.Stdout.String(), "Addresses:"))
|
||||
}
|
||||
|
||||
// TestResolvConfPreservedOnRestart verifies that external modifications to
|
||||
// /etc/resolv.conf are preserved when a non-host network container is restarted.
|
||||
// Regression test for https://github.com/moby/moby/issues/51490
|
||||
func TestResolvConfPreservedOnRestart(t *testing.T) {
|
||||
skip.If(t, testEnv.DaemonInfo.OSType == "windows", "No /etc/resolv.conf on Windows")
|
||||
|
||||
ctx := setupTest(t)
|
||||
|
||||
d := daemon.New(t, daemon.WithResolvConf(network.GenResolvConf("8.8.8.8")))
|
||||
d.StartWithBusybox(ctx, t)
|
||||
defer d.Stop(t)
|
||||
|
||||
c := d.NewClientT(t)
|
||||
defer c.Close()
|
||||
|
||||
const ctrName = "test-resolvconf-preserved-on-restart"
|
||||
id := container.Run(ctx, t, c, container.WithName(ctrName))
|
||||
defer c.ContainerRemove(ctx, id, client.ContainerRemoveOptions{Force: true})
|
||||
|
||||
appendContent := `# hello`
|
||||
res, err := container.Exec(ctx, c, ctrName, []string{
|
||||
"sh", "-c",
|
||||
"echo '" + appendContent + "' >> /etc/resolv.conf",
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.Equal(res.ExitCode, 0))
|
||||
|
||||
// Restart the container.
|
||||
_, err = c.ContainerRestart(ctx, ctrName, client.ContainerRestartOptions{})
|
||||
assert.Assert(t, is.Nil(err))
|
||||
|
||||
// Verify the modification was preserved
|
||||
res, err = container.Exec(ctx, c, ctrName, []string{"tail", "-n", "1", "/etc/resolv.conf"})
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.Equal(res.ExitCode, 0))
|
||||
assert.Check(t, is.Contains(res.Stdout(), appendContent))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user