-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).

1

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This works inside the docker network but not outside the network. I try to access the container from the host.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.