dubbo
dubbo copied to clipboard
Dubbo+SpringBoot应用打包成Docker镜像无法获取DUBBO_IP_TO_REGISTRY
- [x] I have searched the issues of this repository and believe that this is not a duplicate.
- [x] I have checked the FAQ of this repository and believe that this is not a duplicate.
Environment
- Dubbo version: 2.7.3
- Operating System version: OSX 10.15.4
- Java version: OpenJDK 1.8.0_212
Steps to reproduce this issue
- Dockerfile文件
FROM openjdk:8
MAINTAINER [email protected]
RUN echo "Asia/Shanghai" > /etc/timezone && dpkg-reconfigure -f noninteractive tzdata
COPY ./target/dubbo273-0.0.1-SNAPSHOT.jar /dubbo.jar
ENV NACOS_DISCONVER_ADDR ""
ENV DUBBO_REGISTRY_ADDRESS ""
ENV DUBBO_IP_TO_REGISTRY ""
ENV DUBBO_PORT_TO_REGISTRY ""
ENV TZ Asia/Shanghai
EXPOSE ${DUBBO_PORT_TO_REGISTRY}
ENTRYPOINT java -jar /dubbo.jar \
-Djava.security.egd=file:/dev/./urandom \
--spring.cloud.nacos.discovery.server-addr=${NACOS_DISCONVER_ADDR} \
--dubbo.registry.address=${DUBBO_REGISTRY_ADDRESS} \
--dubbo.protocol.port=${DUBBO_PORT_TO_REGISTRY}
- 容器启动语句
sudo docker run --rm --name dubbo273 \
-p 30000:30000 \
-e NACOS_DISCONVER_ADDR=10.0.0.20:8848 \
-e DUBBO_REGISTRY_ADDRESS=spring-cloud://10.0.0.20:8848 \
-e DUBBO_IP_TO_REGISTRY=10.0.0.20 \
-e DUBBO_PORT_TO_REGISTRY=30000 \
demo/dubbo273:0.1
-
Nacos上显示的注册信息

-
容器里获取DUBBO_IP_TO_REGISTRY

-
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>dubbo273</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>dubbo273</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud-alibaba.version>2.1.0.RELEASE</spring-cloud-alibaba.version>
<spring-boot.version>2.1.4.RELEASE</spring-boot.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-registry-nacos</artifactId>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-dubbo</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>${spring-cloud-alibaba.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Expected Result
- 能正确读到DUBBO_IP_TO_REGISTRY的IP
Actual Result
- 即便设置了DUBBO_IP_TO_REGISTRY为宿主机的IP,但dubbo注册的IP是容器的IP,端口是SpringBoot应用的web端口.导致其他服务无法调用此服务.
+1
等待解决
已解决这个问题,需要配置一下
spring: cloud: nacos: username: nacos password: nacos discovery: server-addr: ip:port ip: ${DUBBO_IP_TO_REGISTRY:null}
spring.cloud.nacos.discovery.ip=${DUBBO_IP_TO_REGISTRY} spring.cloud.nacos.discovery.port=${DUBBO_PORT_TO_REGISTRY}
这样配置之后可以正常注册
