关键词:
    dubbo docker IP 端口 port

    原因**
    服务在容器内部时,zookeeper显示的注册IP是容器IP,服务器外部无法访问。

    解决
    使用环境变量:-e DUBBO_IP_TO_REGISTRY=10.20.222.191

    示例:

    1. function random_unused_port {
    2. (netstat --listening --all --tcp --numeric |
    3. sed '1,2d; s/[^[:space:]]*[[:space:]]*[^[:space:]]*[[:space:]]*[^[:space:]]*[[:space:]]*[^[:space:]]*:\([0-9]*\)[[:space:]]*.*/\1/g' |
    4. sort -n | uniq; seq 1 1000; seq 1 65535
    5. ) | sort -n | uniq -u | shuf -n 1
    6. }
    7. RANDOM_PORT=$(random_unused_port)
    8. docker run -di --name=tianyun-test-${RANDOM_PORT} \
    9. -v /lib64:/lib64 \
    10. -e DUBBO_IP_TO_REGISTRY=10.20.222.191 \
    11. -e DUBBO_PORT_TO_REGISTRY=${RANDOM_PORT} \
    12. -p ${RANDOM_PORT}:20880 \
    13. jdk8:8u261 bash

    image.png