Merge pull request #51507 from zhangguanzhang/fix-pause-restart

libnet: setupDNS: don't overwrite user-modified resolv.conf
This commit is contained in:
Rob Murray
2025-11-25 13:53:10 +00:00
committed by GitHub
4 changed files with 117 additions and 15 deletions

View File

@@ -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))
}