ballerina 官方提供了docker 的runtime,还是比较方便的

基本项目创建

  • 使用cli创建项目

按照提示操作就行

ballerina init  -i
  • 项目结构

添加了dockerfile 以及docker-compose 简单http 服务

├── Ballerina.toml
├── Dockerfile
├── README.md
├── docker-compose.yml
├── hello_service.bal
├── target
│ └── hello_service.balx
└── tests
└── hello_service_test.bal
  • 添加简单http server 代码(hello_service.bal)
// A system package containing protocol access constructs
// Package objects referenced with 'http:' in code
import ballerina/http;
import ballerina/io; // A service endpoint represents a listener
endpoint http:Listener listener {
port:9090
}; // A service is a network-accessible API
// Advertised on '/hello', port comes from listener endpoint
service<http:Service> hello bind listener { // A resource is an invokable API method
// Accessible at '/hello/sayHello
// 'caller' is the client invoking this resource
sayHello (endpoint caller, http:Request request) { // Create object to carry data back to caller
http:Response response = new; // Objects and structs can have function calls
response.setTextPayload("Hello Ballerina!\n"); // Send a response back to caller
// Errors are ignored with '_'
// -> indicates a synchronous network-bound call
_ = caller -> respond(response);
}
}

Dockerfile

官方提供了基础镜像 ballerina/ballerina

  • dockerfile
# build stage
# FROM ballerina/ballerina-platform AS build-env
# ADD . /home/ballerina/
# RUN ballerina build hello_service.bal
# RUN ls .
FROM ballerina/ballerina
EXPOSE 9090
COPY hello_service.bal /home/ballerina
RUN ls .
ENTRYPOINT [ "ballerina","run","hello_service.bal" ]

集成docker-compose

  • docker-compose.yml
version: "3"
services:
http:
build: .
image: myhttp
ports:
- "9099:9090"

构建&&运行

docker-compose build
docker-compose up -d

效果

参考资料

https://hub.docker.com/r/ballerina/ballerina-platform/
https://hub.docker.com/r/ballerina/ballerina/
https://github.com/rongfengliang/ballerina-docker-demo

 
 
 
 

ballerina 学习二十五 项目docker 部署&& 运行的更多相关文章

  1. ballerina 学习二十六 项目docker 部署&& 运行(二)

    ballerina 从发布,到现在官方文档的更新也是很给力的,同时也有好多改进,越来越好用了 可以参考官方文档 https://ballerina.io/learn/by-guide/restful- ...

  2. Java开发学习(二十五)----使用PostMan完成不同类型参数传递

    一.请求参数 请求路径设置好后,只要确保页面发送请求地址和后台Controller类中配置的路径一致,就可以接收到前端的请求,接收到请求后,如何接收页面传递的参数? 关于请求参数的传递与接收是和请求方 ...

  3. ballerina 学习二十八 快速grpc 服务开发

    ballerina 的grpc 开发模型,对于开发者来说简单了好多,不是schema first 的方式,而是我们 只要编写简单的ballerina service 就可以了,proto 文件是自动帮 ...

  4. Salesforce LWC学习(二十五) Jest Test

    本篇参看: https://trailhead.salesforce.com/content/learn/modules/test-lightning-web-components https://j ...

  5. ballerina 学习二十九 数据库操作

    ballerina 数据操作也是比较方便的,官方也我们提供了数据操作的抽象,但是我们还是依赖数据库驱动的. 数据库驱动还是jdbc模式的 项目准备 项目结构 ├── mysql_demo │ ├── ...

  6. ballerina 学习二十四 监控ballerina

    ballerina 服务的监控还是比较方便的,以及集成了Prometheus Grafana Jaeger Elastic Stack 监控服务监控的集成 主要包含以下几个步骤 a. 安装docker ...

  7. JavaWeb学习 (二十五)————监听器(Listener)

    一.监听器介绍 1.1.监听器的概念

  8. ballerina 学习二十二 弹性服务

    主要包含断路器模式,负载均衡模式,故障转移,重试 Circuit Breaker 参考代码 import ballerina/http; import ballerina/log; import ba ...

  9. ballerina 学习二十 http/https

    提供http && https server && client 访问功能 client endpoint 说白了就是http client 参考代码 import b ...

随机推荐

  1. CCPC-Wannafly Winter Camp Day1 (Div2, onsite)

    Replay Dup4: 要是不挂机,再多仔细想想就好了 J确实自闭好久,一直在想正确性,最后数据错了,喵喵喵? 还是要保证充足的休息啊,中间睡了一小会儿,也不知道睡了多久,醒来他们就又过了一道 要发 ...

  2. Python: 复数的数学运算

    写的最新的网络认证方案代码遇到了一个难题,唯一的解决办法就是使用复数空间,需要使用复数来执行一些计算操作. 复数可以用使用函数complex(real, imag) 或者是带有后缀j 的浮点数来指定. ...

  3. spring整合ehcache 注解实现查询缓存,并实现实时缓存更新或删除

    写在前面:上一篇博客写了spring cache和ehcache的基本介绍,个人建议先把这些最基本的知识了解了才能对今天主题有所感触.不多说了,开干! 注:引入jar <!-- 引入ehcach ...

  4. presto-cli通过hive查询hdfs

    1.  启动hive metastore 2. 启动hive thrift接口 参考:http://www.cnblogs.com/kisf/p/7497261.html 3. 下载presto se ...

  5. Linux 中各个文件夹的作用

    /  根目录 包含了几乎所的文件目录.相当于中央系统.进入的最简单方法是:cd /. /boot  引导程序,内核等存放的目录 这个目录,包括了在引导过程中所必需的文件.在最开始的启动阶段,通过引导程 ...

  6. img = img1*mask + img2*(1-mask) How do that ?

    原文地址:http://answers.opencv.org/question/160599/img-img1mask-img21-mask-how-do-that/ 如何提高一个简单操作的速度?最后 ...

  7. # 20145122 《Java程序设计》第3周学习总结

    教材学习内容总结 1一类一文件. 2一个原始码中只能有一个公开类,一个类定义产生一个.class文档. 3如果参考名称与数据成员同名时,将参数的值指定给对象的数据成员时要在数据成员前加this. 4当 ...

  8. 《JDK 8.0 学习笔记》1~3章

    第一章 Java平台概论 了解Java的发展历程和相关术语如JDK.JVM.JRE等 第二章 从JDK到IDE 书本介绍了新建Java程序的注意事项以及在cmd和Eclipse环境下如何运行Java, ...

  9. 数据导入(一):Hive On HBase

    Hive集成HBase可以有效利用HBase数据库的存储特性,如行更新和列索引等.在集成的过程中注意维持HBase jar包的一致性.Hive与HBase的整合功能的实现是利用两者本身对外的API接口 ...

  10. fiddler几种功能强大的用法(一)

    参考网址: http://caibaojian.com/fiddler.html http://www.cnblogs.com/tangdongchu/p/4178552.html 1.fiddler ...