A Docker Api client for Elixir
- currently only supports TCP
Add docker_api to your mix.exs
defp deps do
[
{:docker_api, git: "https://github.com/bradleyd/docker_api.git"}
]
endMake sure it gets started
def application do
[applications: [:logger, :docker_api]]
endYou can start it by hand also
DockerApi.start #=> {:ok, []}all\1
{:ok, body, code } = DockerApi.all("127.0.0.1")find\2
{:ok, body, code } = DockerApi.Container.get("127.0.0.1", "12345")find\2
Find can also take a List of hosts to search through.
{:ok, body, code } = DockerApi.Container.get(["127.0.0.1", "10.100.13.21"], "12345")top\2
{:ok, body, code } = DockerApi.Container.top("127.0.0.1", "12345")create\2
{:ok, body, code } = DockerApi.Container.create("127.0.0.1", %{image: "foo"})logs\2
{:ok, body, code } = DockerApi.Container.logs("127.0.0.1", "12345")To run a command on a container, you must create a Exec first.
exec returns a Id to query with
exec\3
payload = %{ "AttachStdin": false, "AttachStdout": true, "AttachStderr": true, "Tty": false, "Cmd": ["date"] }
{:ok, body, code } = DockerApi.Container.exec("127.0.0.1", "12345", payload)
#=> %{ "Id" => "1234556678890" }With our Id in hand we can then get the results of the Exec
exec_start\3
payload = %{"Detach": false, "Tty": true}
{:ok, body } = DockerApi.Container.exec_start("127.0.0.1", "1234556678890", payload)
#=> ["Sun Mar 8 00:25:18 UTC 2015\n"]all\1
{:ok, body, code } = DockerApi.Image.all("127.0.0.1")find\2
{ :ok, body, code } = DockerApi.Image.find("127.0.0.1", "12345")Find also takes a List of hosts. Find will search all hosts in the list for a match with that id
{ :ok, body, code } = DockerApi.Image.find(["127.0.0.1", "10.10.100.12"], "12345")build\3
{:ok, result } = DockerApi.Image.build("127.0.0.1", %{t: "foo", q: 1}, "/tmp/docker_image.tar.gz")- Finish mapping all the API endpoints
- Events do not stream forever; only show because of IO.inspect
- Talk to docker hosts that use credentails/TLS
- Finish docstrings
- Mock all the HTTP calls