Can I setup a docker overlay network without using docker swarm?
Will an overlay network reduce latency?
Most likely no, it adds an additional layer of encapsulation for the IP packets that needs to be processed on each side of the connection. Typically people use the overlay networking to simplify the inter cluster communication and reduce complexity of service discovery (apps can communicate by service name, without looking up an external IP/port on another node.
Do you need Swarm Mode for overlay?
No, but it makes it much easier, to the point that I wouldn’t go back to the old way of running an external key/value db like consul and integrating docker with that. You also can’t mix the old way of configuring overlay network databases with swarm mode, so if you decided to use swarm in the future, you’d need to disable the older k/v database configuration and recreate your overlay networks.
Swarm mode is extremely easy to enable:
docker swarm init
Then follow the instructions to either rerun the init command with needed flags like a network interface, or to join other nodes to the cluster.
Importantly, your containers themselves do not need to be managed by swarm mode, you can leave that to only manage the k/v database for overlay networking. When you create the network, make sure to set it to attachable to allow containers outside of swarm mode to use it:
docker network create -d overlay --attachable overlay-net-name
You can also define that in the compose file, just be sure to specify the network name, and typically that will be external for the services started later.