Newbie step-by-step guide to connect IP in multiple containers on separate hosts

Newbie here to docker. I have two hosts running with container in each that i need to allow communications between for application clustering purposes. Ive searched and read, and have some concepts of docker networks, docker swarm, but its blurry to me on what steps I need to do to allow 2 containers to communicate with each other at the application level.

Please keep it simple!

Thanks, Dave

For standard containers you need to expose ports to let them talk to each other on different hosts/nodes.

Docker Swarm creates a layer on top of the nodes with a virtual network and distributing service containers across nodes.

Maybe start by reading the standard docs.

Thank you. Been in these docs all day. Like I mentioned i have the containers up, operational and can connect to them with browser on the ports i have exposed. Ive been researching overlay networks and trying different things, but the localIP on the container is still the internal IP that is only brodcast inside the docker host.

You need to use docker stack deploy to deploy a service with deploy section in docker-compose.yml.

You can set container count per service by replicas or use mode: global to have one container on every node.

Use placement constraint to pin the service/container to certain nodes.

One container can reach another by simply using the service name, when both are attached to the same Docker overlay network.

See simple Swarm Traefik example.

You will find some more interesting reading at 1 and 2.