ballerina 学习二十五 项目docker 部署&& 运行
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 部署&& 运行的更多相关文章
- ballerina 学习二十六 项目docker 部署&& 运行(二)
ballerina 从发布,到现在官方文档的更新也是很给力的,同时也有好多改进,越来越好用了 可以参考官方文档 https://ballerina.io/learn/by-guide/restful- ...
- Java开发学习(二十五)----使用PostMan完成不同类型参数传递
一.请求参数 请求路径设置好后,只要确保页面发送请求地址和后台Controller类中配置的路径一致,就可以接收到前端的请求,接收到请求后,如何接收页面传递的参数? 关于请求参数的传递与接收是和请求方 ...
- ballerina 学习二十八 快速grpc 服务开发
ballerina 的grpc 开发模型,对于开发者来说简单了好多,不是schema first 的方式,而是我们 只要编写简单的ballerina service 就可以了,proto 文件是自动帮 ...
- Salesforce LWC学习(二十五) Jest Test
本篇参看: https://trailhead.salesforce.com/content/learn/modules/test-lightning-web-components https://j ...
- ballerina 学习二十九 数据库操作
ballerina 数据操作也是比较方便的,官方也我们提供了数据操作的抽象,但是我们还是依赖数据库驱动的. 数据库驱动还是jdbc模式的 项目准备 项目结构 ├── mysql_demo │ ├── ...
- ballerina 学习二十四 监控ballerina
ballerina 服务的监控还是比较方便的,以及集成了Prometheus Grafana Jaeger Elastic Stack 监控服务监控的集成 主要包含以下几个步骤 a. 安装docker ...
- JavaWeb学习 (二十五)————监听器(Listener)
一.监听器介绍 1.1.监听器的概念
- ballerina 学习二十二 弹性服务
主要包含断路器模式,负载均衡模式,故障转移,重试 Circuit Breaker 参考代码 import ballerina/http; import ballerina/log; import ba ...
- ballerina 学习二十 http/https
提供http && https server && client 访问功能 client endpoint 说白了就是http client 参考代码 import b ...
随机推荐
- 根据源Excel文件,新建Excel文件
/** * 描述:根据源Excel文件,创建新的Excel文件 * @param excelFile * @throws CheckException */public static void cre ...
- Ubuntu Server VS Ubuntu Desktop区别
今天有位朋友问我,Ubuntu Server 与 Ubuntu Desktop的区别在哪里!区别如下: SERVER没有GUI SERVER没有一堆的桌面软件 SERVER在编译时使用的参数不一样,会 ...
- LS1021ATWR开发板启动日志分析
一.背景 LS1021ATWR开发板运行官方的openwrt系统 二.日志分析 2.1 linux相关日志 root@OpenWrt:/# reboot 重启 root@OpenWrt:/# [ 2 ...
- about SpringBoot学习后记
<SpringBoot实战>第一章节入门的名称为Spring风云再起 看起来Spring的功能确实受Java开发者喜爱 在SpringBoot中,继续将Spring框架做了另一次的封装使框 ...
- 如何创建.babelrc文件?
方法一: 根目录下,创建 .babelrc. 文件名就可以了! 方法二: git进入根目录,输入 type>.babelrc ,回车即可!
- classloader的演进
classloader从1.6到1.7整体分成了两个版本.重点区别就是并行类加载. 1.6版本 protected synchronized Class loadClass(String name, ...
- python批量修改ssh密码
由于工作需要本文主结合了excel表格,对表格中的ssh密码进行批量修改 以下是详细代码(python3): #!/usr/bin/env python#-*-coding:utf-8-*- impo ...
- YAML(摘录)
YAML:维基百科 一个用来表达数据序列的格式.强调以数据为中心的标记语言. 使用空白符缩进和大量依赖外观的特殊,适合编辑数据结构,配置文件. 基本格式: 缩进/区块 和内置两者格式,来表示array ...
- iOS UI-静态单元格与动态单元格
- Java 调用PHP的Web Service(三)
usoap是PHP环境中的开源soap工具,算是用得比较多的一个工具了. 在utf-8环境中,nusoap可以工作得很好.但是当用于中文环境中时,nusoap经常会出现一些让人不得其解的问题. 最近一 ...