-1

I am creating docker containers inside my java application (using 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.

Note after I start the containers I connect them to a docker network (providing this information just in case).

  • There's [an example of publishing ports in the docker-java wiki](https://github.com/docker-java/docker-java/wiki#create-new-docker-container-and-start-it-with-exposed-ports). – David Maze Jan 17 '20 at 00:48

1 Answers1

0

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.

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.

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.

László Stahorszki
  • 1,102
  • 7
  • 23