Skip to main content
In this tutorial, you’ll learn how to create a custom Docker overlay network, deploy services in both ingress and host publish modes, and clean up all resources. This is essential for scalable, multi-host deployments in Docker Swarm.

1. List Existing Docker Networks

Start by checking the current Docker networks on your Swarm manager:
Example output:
Docker Swarm mode automatically creates two additional networks:

2. Create a Custom Overlay Network

Overlay networks enable containers across multiple Docker hosts to communicate. To create a custom network named kodekloudnet, run:
Verify the new network appears in the list:
Inspect the network’s configuration:
Sample JSON output:
To specify your own IP range, add --subnet and --gateway flags:

3. Deploy a Service in Ingress Mode

Ingress mode distributes traffic across all nodes on the published port. Even if a task isn’t running on a specific node, it will forward traffic to an active task elsewhere.
  • --publish published=80,target=80 uses the Swarm ingress load-balancer.
  • Access the application via any manager or worker node IP:
    http://<node-ip>/

4. Deploy a Service in Host Mode

Host mode binds the published port directly on each node where a task is running. Nodes without a task on port 80 will not respond.
  • Traffic is only served on nodes hosting a task.
  • Ensure your load balancer or DNS directs requests to the correct node IPs.

5. Clean Up Resources

When you’re done, remove the services and the custom network:

Watch Video