place-labs / crystal-docker

Docker Engine API wrapper for crystal-lang
https://aca-labs.github.io/crystal-docker
MIT License
6 stars 3 forks source link

Creating a container hangs #2

Open crooke opened 4 years ago

crooke commented 4 years ago

I'm trying to create a container with host configuration:

require "docker"

client = Docker::Client.new
host_config = {
  port_bindings: {
    {"8000/tcp": [{host_port: "8000"}]},
  },
}
client.containers.create("amazon/dynamodb-local", host_config: host_config)

But when I run crystal run on the file, it hangs indefinitely. I'm using docker-crystal commit: 898cea2884ea1305e49b7e52c5fa5d0553f843c2 with crystal 0.34.0.

I may just be doing something wrong. Any help is appreciated. Thanks!

crooke commented 4 years ago

It seemed like it was the POST request to Docker that was hanging, then I realized I had extra braces in port_bindings, so I fixed that:

host_config = {
  port_bindings: {
    "8000/tcp": [{host_port: "8000"}],
  },
}

However, then I get a compile-time error in crystal-docker:

In lib/docker/src/core_ext/hash/deep_transform_values.cr:30:7

 30 | yield object
      ^---
Error: no overload matches 'Proc(Array(NamedTuple(HostPort: Int32)), Array(NamedTuple(HostPort: Int32)))#call' with type NamedTuple(HostPort: Int32)

Overloads are:
 - Proc(T, R)#call(*args : *T)

If I change lib/docker/src/core_ext/hash/deep_transform_values.cr:30 to return the object directly instead of yielding, it compiles.

The JSON body doesn't get serialized to TitleCase the way I expected: {"HostConfig":{"port_bindings":{"8000/tcp":[{"host_port":8000}]}},"Image":"amazon/dynamodb-local"}. But I can workaround that by just title-casing it myself:

host_config = {
  "PortBindings": {
    "8000/tcp": [{"HostPort": "8000"}],
  },
}
Dmunch04 commented 4 years ago

I ran into the same error as you

Dmunch04 commented 4 years ago

Btw do you happen to know how I would get the output after running the container?

EDIT: I know there's log files stored with the output, but it would be easier if I could access output through the API EDIT: There doesn't seem to be any way to hijack it, like you can in fx. dockerode