gpt4 book ai didi

linux - Docker 容器访问父服务器中的本地主机

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:19:04 26 4
gpt4 key购买 nike

我的 docker 容器没什么问题。我试图通过 curl 从容器访问我的父服务器 localhost,以便在 elasticsearch 中执行查询。 Elastic 仅在父服务器上的本地区域工作。

curl http://127.0.0.1:9200
curl: (7) Failed to connect to 127.0.0.1 port 9200: Connection refused

容器 ip 是 172.17.0.3 并且我能够从父服务器 ping 容器

这是我的 docker 构建

cd ./api_docker
container="$(docker ps | grep "visitors/api:gniewoy" | cut -d " " -f1)"
git reset --hard HEAD &&
git pull &&
composer update &&
docker build -t visitors/api:gniewoy . &&
cd ../
docker kill $container &&
docker run -p 705:80 --env-file docker_api_env -d /etc/docker/

构建后,continer 在端口 705 上工作正常,但只是弹性问题。以下是我的详细信息

"NetworkSettings": {
"Bridge": "",
"SandboxID": "",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"443/tcp": null,
"80/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "705"
}
]
},
"SandboxKey": "",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.3",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "",
"EndpointID": "",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.3",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": ""
}
}
}

我正在使用 Debian 8。谢谢

最佳答案

您需要通过 -p 标签共享端口,例如 -p 9200:9200

这里第一个9200是内部端口,第二个是容器端口。

看看this

关于linux - Docker 容器访问父服务器中的本地主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46372353/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com