Skip to content

Dubbo with Docker: learn how to deploy a dubbo provider project in a Docker Container

Notifications You must be signed in to change notification settings

wuxiao/dubbo-docker-sample

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

有些部署场景需要动态指定服务注册的地址,如docker bridge网络模式下要指定注册宿主机ip以实现外网通信。dubbo提供了两对启动阶段的系统属性,用于设置对外通信的ip、port地址  

  • DUBBO_IP_TO_REGISTRY --- 注册到注册中心的ip地址
  • DUBBO_PORT_TO_REGISTRY --- 注册到注册中心的port端口
  • DUBBO_IP_TO_BIND --- 监听ip地址  
  • DUBBO_PORT_TO_BIND --- 监听port端口
  1. 以上四个配置项均为可选项,如不配置dubbo会自动获取ip与端口,请根据具体的部署场景灵活选择配置。
  2. dubbo支持多协议,如果一个应用同时暴露多个不同协议服务,且需要为每个服务单独指定ip或port,请分别在以上属性前加协议前缀。 如:  
  • HESSIAN_DUBBO_PORT_TO_BIND hessian协议绑定的port
  • DUBBO_DUBBO_PORT_TO_BIND   dubbo协议绑定的port
  • HESSIAN_DUBBO_IP_TO_REGISTRY hessian协议注册的ip
  • DUBBO_DUBBO_PORT_TO_BIND     dubbo协议注册的ip

dubbo-docker-sample工程本地运行流程:

  1. clone工程到本地
git clone [email protected]:dubbo/dubbo-docker-sample.git
cd dubbo-docker-sample
  1. 本地maven打包
mvn clean install  
  1. docker build构建镜像
docker build --no-cache -t dubbo-docker-sample . 

Dockerfile

FROM openjdk:8-jdk-alpine
ADD target/dubbo-docker-sample-0.0.1-SNAPSHOT.jar app.jar
ENV JAVA_OPTS=""
ENTRYPOINT exec java $JAVA_OPTS -jar /app.jar
  1. 从镜像创建容器并运行
# 由于我们使用zk注册中心,先启动zk容器
docker run --name zkserver --restart always -d zookeeper:3.4.9
docker run -e DUBBO_IP_TO_REGISTRY=30.5.97.6 -e DUBBO_PORT_TO_REGISTRY=20881 -p 30.5.97.6:20881:20880 --link zkserver:zkserver -it --rm dubbo-docker-sample

假设宿主机ip为30.5.97.6。
通过环境变量 DUBBO_IP_TO_REGISTRY=30.5.97.6 DUBBO_PORT_TO_REGISTRY=20880 设置provider注册到注册中心的ip、port   通过-p 30.5.97.6:20881:20880做端口映射,其中20880是dubbo自动选择的监听port,由于没有设置监听ip,将监听0.0.0.0即所有ip地址
启动后provider的注册地址为:30.5.97.6:20881,容器的监听地址为:0.0.0.0:20880  

  1. 测试 从另外一个宿主机或容器执行
telnet 30.5.97.6 20881
ls
invoke com.alibaba.dubbo.test.docker.DemoService.hello("world")

About

Dubbo with Docker: learn how to deploy a dubbo provider project in a Docker Container

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 89.7%
  • Dockerfile 10.3%