lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> Hello,
>     I am working on a project using Docker ( http://www.docker.io/ ) to
> provision server instances dynamically and wanted to try to use Lua to
> handle the dynamic provisioning.
>     The Docker server has a daemon listening on a Unix domain socket (
> /var/run/docker.sock ) that implements a REST interface. There are client
> libraries for Python, Ruby, JS, PHP, etc... but not Lua:
> http://docs.docker.io/en/latest/api/remote_api_client_libraries/
>
>     A client is rather straightforward - a simple HTTP client that can
> bind
> to a Unix domain socket path is all you really need. Looking at Luasocket,
> it looks as if the socket.http library could do this, if the right
> function
> is passed in for the create parameter to the request method.

Hello,

this is indeed the case. You need LuaSocket built with
Unix Socket support for that.

You will also need to specify the parameters that are
usually inferred from the URL. For instance:

    local socket = require "socket"
    local socket_unix = require "socket.unix"
    local http = require "socket.http"
    local io = require "io"
    local ltn12 = require "ltn12"

    r,c,h = http.request{
      host = "/var/run/docker.sock",
      path ="/images/json",
      scheme = "http",
      sink = ltn12.sink.file(io.stdout),
      create = socket_unix,
    }

-- 
Pierre Chapuis