关键词:
dubbo docker IP 端口 port
原因**
服务在容器内部时,zookeeper显示的注册IP是容器IP,服务器外部无法访问。
解决
使用环境变量:-e DUBBO_IP_TO_REGISTRY=10.20.222.191
示例:
function random_unused_port {
(netstat --listening --all --tcp --numeric |
sed '1,2d; s/[^[:space:]]*[[:space:]]*[^[:space:]]*[[:space:]]*[^[:space:]]*[[:space:]]*[^[:space:]]*:\([0-9]*\)[[:space:]]*.*/\1/g' |
sort -n | uniq; seq 1 1000; seq 1 65535
) | sort -n | uniq -u | shuf -n 1
}
RANDOM_PORT=$(random_unused_port)
docker run -di --name=tianyun-test-${RANDOM_PORT} \
-v /lib64:/lib64 \
-e DUBBO_IP_TO_REGISTRY=10.20.222.191 \
-e DUBBO_PORT_TO_REGISTRY=${RANDOM_PORT} \
-p ${RANDOM_PORT}:20880 \
jdk8:8u261 bash