[英]From inside of a Docker container, how do I connect to another process listening inside the same container?
I have spent a couple of hours researching this and the consensus seems to be that using host.docker.internal
instead of localhost
should allow one process within a container to connect to another process within the same container.我花了几个小时研究这个问题,似乎一致认为使用
host.docker.internal
而不是localhost
应该允许容器内的一个进程连接到同一容器内的另一个进程。
However, host.docker.internal
does not work for me.但是,
host.docker.internal
对我不起作用。
Environment:环境:
docker run
command running on WSL2 Ubuntu docker run
命令 Ubuntu Command:命令:
docker run -p 80:80
Error错误
Dockerfile
contents Dockerfile
内容
FROM openjdk:17-alpine
COPY xxx/target/AAA.jar AAA.jar
COPY xxx/target/BBB.jar BBB.jar
COPY xxx/target/CCC.jar CCC.jar
COPY ./dockerboot.sh dockerboot.sh
ENTRYPOINT ["sh", "-c", "./dockerboot.sh"]
EXPOSE 80
dockerboot.sh
contents dockerboot.sh
内容
java -jar AAA.jar &
java -jar BBB.jar &
java -jar CCC.jar &
wait
The AAA
, BBB
, CCC
jars contain java Springboot applications listening on ports 80, 8081, and 8082 respectively. AAA
、 BBB
、 CCC
jars 包含java个Springboot应用,分别监听80、8081、8082端口。
The answer is to just use localhost
or 127.0.0.1
.答案是只使用
localhost
或127.0.0.1
。
It turns out the root cause of my issue was unrelated to Docker.networking:事实证明,我的问题的根本原因与 Docker.networking 无关:
One of the microservice jars was malformed ( no main manifest attribute
) and was not starting up correctly, hence, failing to listen on port 8081 and causing Connection refused
.其中一个微服务 jars 格式错误(
no main manifest attribute
)并且没有正确启动,因此无法侦听端口 8081 并导致Connection refused
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.