docker network create -d host mynet
docker run -d --name mymysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -v ${PWD}/data:/var/lib/mysql --network mynet mysql:5.7
docker run -d --name myresty -p 80:80 -v ${PWD}/script:/script -v ${PWD}/data:/data -v ${PWD}/html:/usr/local/openresty/nginx/html -v ${PWD}/config/nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf:ro -v ${PWD}/logs:/usr/local/openresty/nginx/logs --network mynet openresty/openresty:alpine
lua_package_path '/script/?.lua;/script/?/main.lua;;';
resolver 8.8.8.8 ipv6=off;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
location /lua {
default_type text/html;
content_by_lua_block {
local t = require 'test'
ngx.say(t[1].."\n"..t[2]())
}
}
}
local mysql = require "resty.mysql"
local function testmysql()
local db, err = mysql:new()
if not db then
return "failed to instantiate mysql: "
end
db:set_timeout(1000) -- 1 sec
local ok, err, errcode, sqlstate = db:connect{
host = "mymysql",
port = 3306,
database = "mydb",
user = "root",
password = "123456",
-- charset = "utf8",
max_packet_size = 1024 * 1024,
_on_connect_ = function(db)
local res = db:query("set charset utf8mb4 ; SET GLOBAL time_zone = '+8:00'");
end
}
if not ok then
return "failed to connect: "..err
end
end
[error] 6#6: *1 connect() failed (111: Connection refused), client: 172.18.0.1, server: localhost, request: "GET /lua HTTP/1.1", host: "127.0.0.1"