lapis docker 运行说明
2024-09-04 13:39:42
1. lapis docker 镜像制作
因为openresty 新版本一个json 库的问题,我们使用的是 openresty:1.11.2.1 基础镜像
FROM openresty/openresty:1.11.2.1-centos
RUN yum install -y openssl-devel
RUN /usr/local/openresty/luajit/bin/luarocks install luaossl && \
/usr/local/openresty/luajit/bin/luarocks install lapis
ENV PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin
2. 基本项目
备注:基础镜像可以使用上面构建的,同时可以使已经构建好的
docker pull dalongrong/openrestydemogithub:lapis
lapis 项目结构
├── Dockerfile // 项目运行的镜像
├── Dockerfile-base // lapis 镜像基于openresty 官方镜像
├── README.md
└── appdemo // 基本lapis 项目
├── app.lua
├── client_body_temp
├── config.lua
├── fastcgi_temp
├── mime.types
├── models.lua
├── nginx.conf
├── nginx.conf.compiled
├── proxy_temp
├── scgi_temp
└── uwsgi_temp
3. 项目代码说明
主要是app.lua 以及config.lua
app.lua
local lapis = require("lapis")
local db = require("lapis.db")
local app = lapis.Application()
local json = require("cjson");
app:get("/", function()
return "Welcome to Lapis " .. require("lapis.version")
end)
app:get("/user", function()
-- local res = db.query("SELECT * FROM userdemo")
-- return json.encode(res)
local res = db.query("SELECT * FROM userdemo")
return { json= res}
end)
return app
config.lua // 配置数据库访问
local config = require("lapis.config")
config("development", {
mysql = {
host = "mydb",--change to you database url
user = "root",
password = "dalongrong",
database = "userapp"
}
})
Dockerfile
FROM mylapis2:latest
WORKDIR /app
COPY appdemo/ /app
EXPOSE 8080
ENTRYPOINT ["lapis"]
CMD ["server", "development"]
4. 运行
docker build -t mylapis .
docker run -d -p 8085:8080 mylapis
5. 参考资料
https://github.com/rongfengliang/openrestydemogithub
http://leafo.net/lapis/reference/actions.html#routes-and-url-patterns/route-precedence
https://github.com/rongfengliang/golangmysql-docker
最新文章
- jQuery学习过程问题笔记
- [转] MemCached 的 stats 命令
- 非正规写法获取不到tr,td
- CAPI学习心得
- JavaScript实用技巧总结
- Thrift在Windows及Linux平台下的安装和使用示例
- WF4 常用类<;第二篇>;
- 【Android - MD】之TabLayout的使用
- jQuery--效果和遍历
- 跟着Android学设计模式:代理(proxy)
- androidHandler讲解
- workday1
- js时间戳和日期字符串相互转换
- Spring Cloud 服务端注册与客户端调用
- hdu1814 Peaceful Commission
- Java 跨平台原理
- 马昕璐 201771010118《面向对象程序设计(java)》第十五周学习总结
- Ubuntu离线安装docker
- MySQL之数据导入导出
- 博客搬家了,新域名dinphy.wang