···139139140140In each section below I lightly cover the differences between SWAG/Traefik, what was needed to migrate to Traefik, and how I implemented it along with examples, if necessary.
141141142142+> This guide and the [companion repository](https://github.com/FoxxMD/traefik-homelab) use **user-defined docker networks** for all examples. To make these examples work you will first need to create these OR modify the examples to use default bridge networking (`HOST_IP:PUBLISHED_PORT`). [**See networking differences and guide networking setup below for instructions.**](#user-defined-vs-default-bridge-networking)
143143+{: .prompt-warning}
144144+142145### Web Routing Parity
143146144147This was the hardest requirement to meet for **edge cases**. Unlike NGINX,
···1589159215901593See the [traefik repository for a full stack with Logdy config included.](https://github.com/FoxxMD/traefik-homelab/blob/main/traefik_internal/compose.yaml#L77)
1591159415951595+### User-Defined vs Default Bridge Networking
15961596+15971597+This guide and companion repository exclusively use [intra-stack](https://docs.docker.com/compose/how-tos/networking/) and [`external`](https://docs.docker.com/reference/compose-file/networks/#external), [`attachable`](https://docs.docker.com/reference/compose-file/networks/#attachable) [user-defined `bridge`](https://docs.docker.com/engine/network/drivers/bridge/#differences-between-user-defined-bridges-and-the-default-bridge) (or [**overlay**](#swarm-and-overlay)) [networks](https://docs.docker.com/compose/how-tos/networking/).
15981598+15991599+Using these networks allows all related services to be addressed by their **container name** and **internal** ports which removes the need to hardcode IP addresses, publish ports, and makes the examples in this guide portable.
16001600+16011601+You *should* use user-defined networks if you plan to implement the [separating internal/external sevices section](#separating-internalexternal-services) but for all the other sections its not *required* (but strongly encouraged!). If you do not want to use external networks you can simply replace instances of `container_name:internal_port` in stacks/ENVs with `host_ip:published_port`.
16021602+16031603+<details markdown="1">
16041604+16051605+<summary>Examples of Differences</summary>
16061606+16071607+<details markdown="1">
16081608+16091609+<summary>User-Defined Networks</summary>
16101610+16111611+```yaml
16121612+services:
16131613+ traefik:
16141614+ # ...
16151615+ traefik-redis:
16161616+ container_name: traefik_internal_redis
16171617+ image: redis:7-alpine
16181618+ networks:
16191619+ - kop_overlay
16201620+ - default
16211621+ # ...
16221622+networks:
16231623+ kop_overlay:
16241624+ external: true
16251625+```
16261626+{: file="traefik_internal/compose.yaml"}
16271627+16281628+```yaml
16291629+services:
16301630+ traefik-kop:
16311631+ image: "ghcr.io/jittering/traefik-kop:latest"
16321632+ networks:
16331633+ - kop_overlay
16341634+ - default
16351635+ environment:
16361636+ - "REDIS_ADDR=traefik_internal_redis:6379" # automatically resolves to an internal docker network IP like 10.0.2.14
16371637+ # ...
16381638+networks:
16391639+ kop_overlay:
16401640+ external: true
16411641+```
16421642+{: file="traefik_kop/compose.yaml"}
16431643+16441644+</details>
16451645+16461646+<details markdown="1">
16471647+16481648+<summary>Default Bridge Networking</summary>
16491649+16501650+```yaml
16511651+services:
16521652+ traefik:
16531653+ # ...
16541654+ traefik-redis:
16551655+ container_name: traefik_internal_redis
16561656+ image: redis:7-alpine
16571657+ networks:
16581658+ - default
16591659+ ports:
16601660+ - "7000:6379"
16611661+ # ...
16621662+```
16631663+{: file="traefik_internal/compose.yaml"}
16641664+16651665+```yaml
16661666+services:
16671667+ traefik-kop:
16681668+ image: "ghcr.io/jittering/traefik-kop:latest"
16691669+ networks:
16701670+ - default
16711671+ environment:
16721672+ - "REDIS_ADDR=192.168.0.100:7000" # IP is docker host machine LAN address
16731673+ # ...
16741674+```
16751675+{: file="traefik_kop/compose.yaml"}
16761676+16771677+</details>
16781678+16791679+</details>
16801680+16811681+#### Setup Networks from Guide
16821682+16831683+There are four user-defined networks used in this guide and [companion repository.](https://github.com/FoxxMD/traefik-homelab?tab=readme-ov-file#networks)
16841684+16851685+If you plan on using this guide to setup Traefik for traffic over multiple machines you will need to setup [Swarm and Overlay](#swarm-and-overlay) networks to use them. If you do not set this up you will need to use Default Bridge Networking for any example that communicates between different machines.
16861686+16871687+If all setup is being done on one machine then you can still use the user-defined networks below, just replace `--driver=overlay` with `--driver=bridge`.
16881688+16891689+Reference [Creating Docker Networks](https://docs.docker.com/reference/cli/docker/network/create/)
16901690+16911691+```shell
16921692+docker network create --driver=overlay --attachable internal_overlay
16931693+docker network create --driver=overlay --attachable --subnet=10.99.0.0/24 public_overlay
16941694+docker network create --driver=overlay --internal --attachable kop_overlay
16951695+docker network create --driver=overlay --internal --attachable crowdsec_overlay
16961696+```
16971697+16981698+Any unused subnet can be used for `public_overlay`.
16991699+15921700### Swarm and Overlay
1593170115941702#### What/Why Overlay?
1595170315961596-[Docker Networks](https://docs.docker.com/engine/network/) provide many benefits to the containers attached to them like network isolation and automatic hostname resolution to private IP in the network (reach by container name IE `http://myContainerName` => `http://10.0.5.26`). However, with (Standalone) Docker all of the [Networks types](https://docs.docker.com/engine/network/drivers/) that can be created (`host bridge ipvlan`) can only be used on the same machine they were created on. If you need containers on different hosts to communicate this can only be done through the [host `bridge`](https://docs.docker.com/engine/network/drivers/bridge/) and the remote container must publish a port to its host IE `http://HOST_IP:PORT` => `http://192.168.0.1:5770`.
17041704+[User-Defined Docker Networks](https://docs.docker.com/engine/network/drivers/bridge/#differences-between-user-defined-bridges-and-the-default-bridge) provide many benefits to the containers attached to them like network isolation and automatic hostname resolution to private IP in the network (reach by container name IE `http://myContainerName` => `http://10.0.5.26`). However, with (Standalone) Docker all of the [Networks types](https://docs.docker.com/engine/network/drivers/) that can be created (`host bridge ipvlan`) can only be used on the same machine they were created on. If you need containers on different hosts to communicate this can only be done through the [default `bridge` network](https://docs.docker.com/engine/network/drivers/bridge/) and the remote container must publish a port to its host IE `http://HOST_IP:PORT` => `http://192.168.0.1:5770`.
1597170515981598-There is *another* network type, [**Overlay**](https://docs.docker.com/engine/network/drivers/overlay/), that solves this problem. Overlay networks *span all hosts* by communicating through internal bridges on each host's Docker daemon. All of the benefits (network isolation, hostname resolution, etc...) of a docker network are preserved but the containers can be running on any host attached to the network. However, **to use this network type your hosts must be in a [Docker Swarm](https://docs.docker.com/engine/swarm/).**
17061706+There is *another* user-defined network type, [**Overlay**](https://docs.docker.com/engine/network/drivers/overlay/), that solves this problem. Overlay networks *span all hosts* by communicating through internal bridges on each host's Docker daemon. All of the benefits (network isolation, hostname resolution, etc...) of a user-defined docker network are preserved but the containers can be running on any host attached to the network. However, **to use this network type your hosts must be in a [Docker Swarm](https://docs.docker.com/engine/swarm/).**
1599170716001708#### Should You Swarm?
16011709···1658176616591767This must be done from a manager node. After creating the network, it will only be listed on a host's networks (`docker network ls`) *if there is an existing container attached to it.*
1660176816611661-If you are creating an overlay network for [use with external traefik services (following this guide)](#by-isolated-docker-network) then make sure to [specify an unused subnet](https://docs.docker.com/reference/cli/docker/network/create/#specify-advanced-options) that can be used for firewall rules later (next post!)
16621662-16631663-16641664-```shell
16651665-docker network create --driver=bridge --attachable --subnet=10.99.0.0/24 public_net
16661666-```
17691769+**Follow the instructions from the [networking setup section above](#setup-networks-from-guide) to create the overlay networks needed for this guide.**
1667177016681771To use an overlay network in a compose stack, it must be defined in [top-level networking](https://docs.docker.com/reference/compose-file/networks/) as [`external`](https://docs.docker.com/reference/compose-file/networks/#external):
16691772