This page will explain how I use docker networking in my apps.
With Docker standalone
Section titled “With Docker standalone”My docker networking is pretty straight forward tbh. I use a single network called homelab using the docker bridge driver_._
Creating the network
Section titled “Creating the network”Run the following command :
docker network create -d bridge homelab
Using the network
Section titled “Using the network”- In a run command add following arg :
docker run [...] --network=homelab
- Using docker-compose :
version: "3"services: app: # ... networks: - homelab
networks: homelab: external: true
Comments
Section titled “Comments”By default docker resolve hostname using the container name but specifying one can be done as follow :
- In a docker run command :
--hostname=[container-name]
- In a docker-compose file :
hostname: [container-name]
With Docker swarm
Section titled “With Docker swarm”We do use a same homelab network for all our services but first we need to adjust a few things. Indeed, since we’re using Tailscale between our nodes, we need to adjust the MTU of the network to corresponds to Tailscale one (1280).
Creating the network
Section titled “Creating the network”First let’s delete the default ingress network
docker network rm ingress
Then we create it but with the good MTU, along with the homelab network :
docker network create -d overlay --ingress --opt com.docker.network.driver.mtu=1280 ingressdocker network create -d overlay --attachable --opt com.docker.network.driver.mtu=1280 homelab
Using the network
Section titled “Using the network”Now we can use it anywhere in our stacks like so :
version: "3"services: app: # ... networks: - homelab
networks: homelab: external: true