linux - Communication between linked docker containers -
i have 2 docker containers in following setup on host machine:
- container 1 - udp port 5043 mapped host port 5043 (0.0.0.0:5043:5043)
- container 2 - needs send data container 1 on port 5043 udp.
scenario 1
- i start container 1 , obtain it's ip address.
- i use ip address , configure container 2 , start it.
- container 2 able send udp data container 1 calling
udp://container_1_ip:5043
everything works!!
scenario 2
- i start container 1 mapping 5043 udp port host's 5043 port (
0.0.0.0:5043:5043
) - i link container 2 , container 1 using '
--links
'. - now, when container 2 invokes url
udp://container_1_ip:5043
, error thrown "connection refused
". - i did verify able ping container 1 inside container 2 using ip.
any scenario 2 working me appreciated!!
as mentioned in docker links:
docker defines set of environment variables each port exposed source container.
each variable has unique prefix in form:
<name>_port_<port>_<protocol>
the components in prefix are:
- the alias specified in --link parameter (for example, webdb)
- the
<port>
number exposed- a
<protocol>
either tcp or udp
that means need make sure container1 exposes right port right protocol (in case, udp): see "how expose udp port on docker?"