mirror of
https://github.com/containers/podman.git
synced 2025-08-06 03:19:52 +08:00
Don't delete another container's resolv and hosts files
The logic of deleting and recreating /etc/hosts and /etc/resolv.conf only makes sense when we're the one that creates the files - when we don't, it just removes them, and there's nothing left to use. Fixes #2602 Signed-off-by: Matthew Heon <matthew.heon@pm.me>
This commit is contained in:
@ -665,18 +665,21 @@ func (c *Container) makeBindMounts() error {
|
||||
|
||||
if !netDisabled {
|
||||
// If /etc/resolv.conf and /etc/hosts exist, delete them so we
|
||||
// will recreate
|
||||
if path, ok := c.state.BindMounts["/etc/resolv.conf"]; ok {
|
||||
if err := os.Remove(path); err != nil && !os.IsNotExist(err) {
|
||||
return errors.Wrapf(err, "error removing container %s resolv.conf", c.ID())
|
||||
// will recreate. Only do this if we aren't sharing them with
|
||||
// another container.
|
||||
if c.config.NetNsCtr == "" {
|
||||
if path, ok := c.state.BindMounts["/etc/resolv.conf"]; ok {
|
||||
if err := os.Remove(path); err != nil && !os.IsNotExist(err) {
|
||||
return errors.Wrapf(err, "error removing container %s resolv.conf", c.ID())
|
||||
}
|
||||
delete(c.state.BindMounts, "/etc/resolv.conf")
|
||||
}
|
||||
delete(c.state.BindMounts, "/etc/resolv.conf")
|
||||
}
|
||||
if path, ok := c.state.BindMounts["/etc/hosts"]; ok {
|
||||
if err := os.Remove(path); err != nil && !os.IsNotExist(err) {
|
||||
return errors.Wrapf(err, "error removing container %s hosts", c.ID())
|
||||
if path, ok := c.state.BindMounts["/etc/hosts"]; ok {
|
||||
if err := os.Remove(path); err != nil && !os.IsNotExist(err) {
|
||||
return errors.Wrapf(err, "error removing container %s hosts", c.ID())
|
||||
}
|
||||
delete(c.state.BindMounts, "/etc/hosts")
|
||||
}
|
||||
delete(c.state.BindMounts, "/etc/hosts")
|
||||
}
|
||||
|
||||
if c.config.NetNsCtr != "" {
|
||||
|
Reference in New Issue
Block a user