2023-02-17
I had a problem this morning: each container will have a different name, and therefore it won’t be possible for a proxy container to know at build time other containers name. So I could not use ProxyPassMatch ... fastcgi://php-fpm:9000
in my Apache config (php-fpm would be resolve as the real container ip address)
However, within a pod it seams like every container has the same localhost, and therefor I can use something like ProxyPassMatch fastcgo://127.0.0.1:9000
. I discovered that by creating a pod and running a container inside, then cat /etc/host
which revealed that the containers’ hostname were mapped to 127.0.0.1.
To demonstrate this, first create a pod:
1
podman pod create --name nc-test
Then run a container running netcat in listening mode, and another that will send a message using the hostname of the listener:
1 2
podman run --rm --pod nc-test --name alp1 docker.io/library/alpine:latest nc -l -p 2589 podman run --rm --pod nc-test --name alp2 docker.io/library/alpin
e:latest sh -c ’echo “hello world” | nc alp1 2589'
1 2 3 4 5
The listener show `hello world`. Now let's do the same, but this time the sender will use 127.0.0.1: ```bash podman run --rm --pod nc-test --name alp1 docker.io/library/alpin
e:latest nc -l -p 2589
podman run –rm –pod nc-test –name alp2 docker.io/library/alpin
e:latest sh -c ’echo “hello world” | nc 127.0.0.1 2589'
1 2
It shows `hello world` too!