summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authoropenshift-ci[bot] <75433959+openshift-ci[bot]@users.noreply.github.com>2021-08-04 15:34:58 +0000
committerGitHub <noreply@github.com>2021-08-04 15:34:58 +0000
commit6ff19643007303a35fcc0f7b7aa611ffcc1c5d5c (patch)
tree23b2e1178dccb6c138834e6ffab89848692e0b1d /libpod
parent8aa869e6288997f01ddb7b8daf78e0edb653fc13 (diff)
parentcfcd1e1863ad4fb31476364bde64a70dc1f1196c (diff)
downloadpodman-6ff19643007303a35fcc0f7b7aa611ffcc1c5d5c.tar.gz
podman-6ff19643007303a35fcc0f7b7aa611ffcc1c5d5c.tar.bz2
podman-6ff19643007303a35fcc0f7b7aa611ffcc1c5d5c.zip
Merge pull request #11118 from mheon/use_host_resolveconf
Do not add an entry to /etc/hosts with `--net=host`
Diffstat (limited to 'libpod')
-rw-r--r--libpod/container_internal_linux.go38
1 files changed, 18 insertions, 20 deletions
diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go
index bff64aa95..f30f622ac 100644
--- a/libpod/container_internal_linux.go
+++ b/libpod/container_internal_linux.go
@@ -1912,6 +1912,7 @@ func (c *Container) appendHosts(path string, netCtr *Container) (string, error)
// and returns a string in a format that can be written to the host file
func (c *Container) getHosts() string {
var hosts string
+
if len(c.config.HostAdd) > 0 {
for _, host := range c.config.HostAdd {
// the host format has already been verified at this point
@@ -1922,36 +1923,33 @@ func (c *Container) getHosts() string {
hosts += c.cniHosts()
- // If not making a network namespace, add our own hostname.
+ // Add hostname for slirp4netns
if c.Hostname() != "" {
if c.config.NetMode.IsSlirp4netns() {
// When using slirp4netns, the interface gets a static IP
slirp4netnsIP, err := GetSlirp4netnsIP(c.slirp4netnsSubnet)
if err != nil {
- logrus.Warn("failed to determine slirp4netnsIP: ", err.Error())
+ logrus.Warnf("failed to determine slirp4netnsIP: %v", err.Error())
} else {
hosts += fmt.Sprintf("# used by slirp4netns\n%s\t%s %s\n", slirp4netnsIP.String(), c.Hostname(), c.config.Name)
}
- } else {
- hasNetNS := false
- netNone := false
- for _, ns := range c.config.Spec.Linux.Namespaces {
- if ns.Type == spec.NetworkNamespace {
- hasNetNS = true
- if ns.Path == "" && !c.config.CreateNetNS {
- netNone = true
- }
- break
+ }
+
+ // Do we have a network namespace?
+ netNone := false
+ for _, ns := range c.config.Spec.Linux.Namespaces {
+ if ns.Type == spec.NetworkNamespace {
+ if ns.Path == "" && !c.config.CreateNetNS {
+ netNone = true
}
+ break
}
- if !hasNetNS {
- // 127.0.1.1 and host's hostname to match Docker
- osHostname, _ := os.Hostname()
- hosts += fmt.Sprintf("127.0.1.1 %s %s %s\n", osHostname, c.Hostname(), c.config.Name)
- }
- if netNone {
- hosts += fmt.Sprintf("127.0.1.1 %s %s\n", c.Hostname(), c.config.Name)
- }
+ }
+
+ // If we are net=none (have a network namespace, but not connected to
+ // anything) add the container's name and hostname to localhost.
+ if netNone {
+ hosts += fmt.Sprintf("127.0.0.1 %s %s\n", c.Hostname(), c.config.Name)
}
}