network_mode details

tags: learning linux networking

content

  • when a service uses network_mode: container:<name>, it uses the same network namespace of another container, which means:
    • same ip address
    • same localhost
  • if there’s a service running on 127.0.0.1:80, either container can access with this ip:port
  • network_mode has an implicit dependency
    • the one that has network_mode depends on the one in the value
  • one container can have multiple sidecars
  • below, sidecar depends on web and uses web’s network stack
services:
	web:
		image: nginx 
	sidecar:
		image: busybox
		network_mode: "container:web"
	sidecar2:
		image: alpine
		network_mode: "container:web"

up

down

reference