10.9. Communicating between two containers in a pod
All containers in the same pod share the IP addresses, MAC addresses and port mappings. You can communicate between containers in the same pod using localhost:port notation.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Create a pod named
web-pod:$ podman pod create --name=web-podRun the web container named
web-containerin the pod:$ podman container run -d --pod web-pod --name=web-container docker.io/library/httpdList all pods and containers associated with them:
$ podman ps --pod CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES POD ID PODNAME 58653cf0cf09 k8s.gcr.io/pause:3.5 4 minutes ago Up 3 minutes ago 4e61a300c194-infra 4e61a300c194 web-pod b3f4255afdb3 docker.io/library/httpd:latest httpd-foreground 3 minutes ago Up 3 minutes ago web-container 4e61a300c194 web-podRun the container in the
web-podbased on the docker.io/library/fedora image:$ podman container run -it --rm --pod web-pod docker.io/library/fedora curl localhostYou can see that the container can reach the
web-container.