TritonDataCenter / sdc-docker

Docker Engine for Triton
Mozilla Public License 2.0
182 stars 49 forks source link

Containers with volumes defined in Terraform report "host volumes are not supported" #117

Closed cmacrae closed 7 years ago

cmacrae commented 7 years ago

Overview

I'm trying to define a container with a volume in Terraform for my on-prem install of SDC.
I understand the restrictions outlined here.
I've defined a container volume with 'container path' and 'volume name' properties, with the intention of using it to preserve data for another container (for use with 'volumes from') across upgrades/reprovisions.

However, despite passing no host volume parameters (this is just a container volume), the SDC Docker API returns a 500, stating 'host volumes are not supported'.

The Terraform declaration

resource "docker_container" "gogs_data" {
  image   = "${docker_image.alpine.latest}"
  name    = "gogs_data"
  volumes = {
    volume_name    = "data"
    container_path = "/data"    
  }
}

The error returned

Error applying plan:

1 error(s) occurred:

* docker_container.gogs_data: Unable to create container: API error (500): host volumes are not supported (fb24ffbf-db0f-4f92-9720-2c2f37876683)

Workarounds

I'm able to create such a container, with the same properties, using the standard docker command, though there is a strange responses during:

$ docker run -d -v /gogs_data --name gogs_data alpine:latest true 
bfb113a6341ae345c125b144fed755965cf72583a43245e1b368d81c9faafd9b
ERRO[0010] error getting events from daemon: Error response from daemon: (NotImplemented) events is not implemented (c0e6796b-23fd-4508-8f07-def38e3ca460)

$ docker run -it --volumes-from gogs_data --name gogs_test alpine:latest sh
ERRO[0010] error getting events from daemon: Error response from daemon: (NotImplemented) events is not implemented (1bcb5e00-e678-4f0a-8e4d-94061478dbba)
/ # ls -ld /gogs_data/
drwxr-xr-x    2 root     wheel            2 May  8 19:07 /gogs_data/

So, as you can see, it does indeed work. Just that for some reason, when defined via Terraform, the API seems to think I'm attempting to create a container with a host volume.

Please do let me know if there's any further debugging information I can provide, or any steps I can take to help out.

askfongjojo commented 7 years ago

Hi @cmacrae - It looks like Terraform translates the volume request to map a local volume to a host volume of the same name, i.e. turning it into something like:

docker run -d -v /gogs_data:/gogs_data --name gogs_data alpine:latest true 

To confirm this, you can check the docker log files to see if the request is passing host volume info (specifically the HostConfig.Binds property in the request payload).

cmacrae commented 7 years ago

Hey @askfongjojo - thanks for your response. Yeah, this was my inkling, too.
Thanks for the debugging tip, I'm away for a long weekend, but will take a look at the logs when I'm back and confirm.

If it is the case that Terraform is doing so, I'll raise the issue with them.

cmacrae commented 7 years ago

@askfongjojo Sorry for the late response.
I can confirm Terraform is changing the mapping to include a host configuration binding:

      "Volumes": {
        "/data": {}
      },
      "Entrypoint": null,
      "HostConfig": {
        "Binds": [
          "data:/data:rw"
        ],

I'll raise this with the Terraform guys - thanks for your help 👍