GithubHelp home page GithubHelp logo

kiddofun / dubbo-docker-sample Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ahaisong/dubbo-docker-sample

0.0 2.0 0.0 59 KB

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

Dockerfile 10.32% Java 89.68%

dubbo-docker-sample's Introduction

有些部署场景需要动态指定服务注册的地址,如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")

dubbo-docker-sample's People

Contributors

chickenlj avatar donhui avatar oldratlee avatar

Watchers

James Cloos avatar byio avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.