lapis docker 运行说明

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
原文地址:https://www.cnblogs.com/rongfengliang/p/8624712.html