Mark Tickner
Mark Tickner

Reputation: 1053

Inter-container connection via localhost

I would like to set up my containers so that they connect to each other via localhost.

My setup is a main application container and two other containers that it needs to connect to (ActiveMQ and Wiremock).

I already run ActiveMQ and Wiremock in containers with the relevant ports exposed, and the main application runs through IntelliJ and connects to these. However, when I am not developing the main applications, I would like to run it in a container for simplicity but it cannot connect to the ports exposed by the others.

Setting --net=host doesn't seem to work, nor does creating a network docker network create <NAME> and assigning it in the docker run with --net=<NAME>.

The application already runs in a container in other environments on the host network.

Upvotes: 1

Views: 463

Answers (1)

Derick Bailey
Derick Bailey

Reputation: 72868

docker creates a default network in which all containers run, and sets a network name for each of your containers, using the container name.

if you have a contained named mq for your ActiveMQ, then you would use something like tcp://mq:61616 (or whatever protocol / port you have configured) from your other containers, to connect to it.

you shouldn't need to set the --net option unless you need to create a specific network for specific containers to use.

Upvotes: 1

Related Questions