Because the network namespace between different containers is isolated, the localhost loopback address of each container can only point to itself However, in k8s, containers in the same pod can actually use localhost to access each other. Why? K8s’s pod will run a container named pause by default, and other containers will be hung on this pause, that is, the docker run –net container is used
docker run -i -t --name pause busybox sleep infinity
docker run -i -t --name nginx --net container:pause nginx
docker run -i -t --name watcher --net container:pause ubuntu sleep infinity
docker exec -i -t watcher /bin/bash
in the container
apt update
apt install curl
curl localhost:80