首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法用allow_host_loopback=true解析DNS

无法用allow_host_loopback=true解析DNS
EN

Stack Overflow用户
提问于 2021-07-20 07:30:42
回答 1查看 1.3K关注 0票数 2

我正在尝试给部署中的一个容器选项,以到达主机回送IP。然而,在容器级别上这样做会破坏到达其他容器的方式。

基本设置:

代码语言:javascript
运行
复制
podman pod create --name "mypod"

podman run -d \
    --pod mypod \
    --name "nginx" \
    --restart "on-failure" \
    docker.io/library/nginx:1.19

podman run -it \
    --pod mypod \
    --name "curler" \
    docker.io/library/alpine:3.11 sh -c "apk add curl; curl nginx"

在这里,我从nginx获得了预期的HTML结果:

代码语言:javascript
运行
复制
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

但是,当我将allow_host_loopback选项添加到吊舱内的容器时,主机突然无法通过curl解析:

代码语言:javascript
运行
复制
podman pod create --name "mypod"

podman run -d \
    --pod mypod \
    --net slirp4netns:allow_host_loopback=true \
    --name "nginx" \
    --restart "on-failure" \
    docker.io/library/nginx:1.19

podman run \
    --pod mypod \
    --name "curler" \
    docker.io/library/alpine:3.11 sh -c "apk add curl; curl nginx"

curl:(6)无法解析主机: nginx

在将allow_host_loopback选项添加到pod时,可以再次解析DNS名称:

代码语言:javascript
运行
复制
podman pod create \
    --name mypod \
    --net slirp4netns:allow_host_loopback=true

podman run -d \
    --pod mypod \
    --name "nginx" \
    --restart "on-failure" \
    docker.io/library/nginx:1.19

podman run \
    --pod mypod \
    --name "curler" \
    docker.io/library/alpine:3.11 sh -c "apk add curl; curl nginx"
代码语言:javascript
运行
复制
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

podman version输出

代码语言:javascript
运行
复制
Version:      3.1.2
API Version:  3.1.2
Go Version:   go1.15.2
Built:        Thu Jan  1 01:00:00 1970
OS/Arch:      linux/amd64

在第二种情况下,网络会发生什么变化,从而无法解析DNS名称?我有办法让一个集装箱到达回环,但不是全部?

EN

回答 1

Stack Overflow用户

发布于 2021-12-07 11:29:53

这个问题在一个GitHub问题上得到了回答,参见此处:https://github.com/containers/podman/issues/10988

这种行为是预料之中的。当您使用pod时,所有容器都共享网络命名空间,并可以通过回送接口进行通信。当向容器添加-net slirp4netns时,它将覆盖默认的pod网络命名空间,并为该容器创建一个具有slirp4netns的新网络命名空间。因此,它不能再通过127.0.0.1访问其他容器。

这种行为也在文档:https://github.com/containers/podman/blob/main/docs/source/markdown/podman-create.1.md#--networkmode---net中作了概述。

如果与--

一起使用,容器将不会加入该荚的网络命名空间.

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68451126

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档