简体   繁体   English

docker-java:访问 docker 主机上的容器

[英]docker-java: access containers on docker host

I am creating docker containers inside my java application (using docker-java ).我正在我的 java 应用程序中创建 docker 容器(使用docker-java )。 I want to make the containers (all from the same image) accessible for the host.我想让主机可以访问容器(都来自同一个图像)。

Preferably all the containers listen on the same port, thus their IP address needs to change.最好所有的容器都监听同一个端口,因此它们的 IP 地址需要更改。

Note after I start the containers I connect them to a docker network (providing this information just in case).请注意,在我启动容器后,我将它们连接到 docker 网络(提供此信息以防万一)。

While I'm familiar with Java and Docker as well, I'm not familiar with "docker-java", so take what I say with a grain of salt.虽然我对 Java 和 Docker 也很熟悉,但我对“docker-java”并不熟悉,所以对我所说的持保留态度。

I'd try and make use of the feature of docker networks that they act as a DNS servers for the containers connected to them.我会尝试利用 docker 网络的功能,它们充当连接到它们的容器的 DNS 服务器。

What that means is that if you have a container called docker_task with a listener on port 8080, you can make a request to docker_task:8080 and expect the network to resolve docker_task to the appropriate IP address.这意味着,如果您有一个名为docker_task的容器,在端口 8080 上有一个侦听器,您可以向docker_task:8080发出请求,并期望网络将docker_task解析为适当的 IP 地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM