Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker_container volumes host_path ignored #87

Open
mavogel opened this issue Dec 25, 2020 · 6 comments
Open

docker_container volumes host_path ignored #87

mavogel opened this issue Dec 25, 2020 · 6 comments
Labels
bug Something isn't working pinned r/container Relates to the container resource

Comments

@mavogel
Copy link
Contributor

mavogel commented Dec 25, 2020

This issue was originally opened by @schlitzered as hashicorp/terraform-provider-docker#139. It was migrated here as a result of the community provider takeover from @kreuzwerker. The original body of the issue is below.


Terraform Version

Terraform v0.11.13

  • provider.docker v1.1.1

Affected Resource(s)

docker_container

Terraform Configuration Files

resource "docker_container" "fdsafx_dev" {
  image   = "${docker_image.fdsafx_dev.latest}"
  name    = "fdsafx_dev"
  privileged = true
  entrypoint = [
    "/usr/sbin/init"
  ]
  volumes = {
    volume_name    = "www_fdsafx_test"
    read_only      = false
    host_path = "/Users/MyUser/tmp/docker_fdsafx/terraform/blarg/"
    container_path = "/www/fdsafx_test"
  }
}

Expected Behavior

container should have /Users/MyUser/tmp/docker_fdsafx/terraform/blarg/ mounted

Actual Behavior

container has /var/lib/docker/volumes/www_fdsafx_test/_data mounted

Steps to Reproduce

  1. terraform apply

Important Factoids

running on MacOS useing Docker Desktop

from docker inspect:

        "Mounts": [
            {
                "Type": "volume",
                "Name": "www_fdsafx_test",
                "Source": "/var/lib/docker/volumes/www_fdsafx_test/_data",
                "Destination": "/www/fdsafx_test",
                "Driver": "local",
                "Mode": "rw",
                "RW": true,
                "Propagation": ""
            }
        ],
@mavogel mavogel added r/container Relates to the container resource bug Something isn't working labels Dec 25, 2020
@github-actions
Copy link

This issue is stale because it has been open 60 days with no activity.
Remove stale label or comment or this will be closed in 7 days.
If you don't want this issue to be closed, please set the label pinned.

@github-actions github-actions bot added the stale label Mar 29, 2021
@github-actions github-actions bot closed this as completed Apr 6, 2021
@mavogel mavogel removed the stale label Apr 7, 2021
@mavogel mavogel reopened this Apr 7, 2021
@github-actions
Copy link

github-actions bot commented Jun 6, 2021

This issue is stale because it has been open 60 days with no activity.
Remove stale label or comment or this will be closed in 7 days.
If you don't want this issue to be closed, please set the label pinned.

@github-actions github-actions bot added the stale label Jun 6, 2021
@mavogel mavogel added pinned and removed stale labels Jun 14, 2021
@mafredri
Copy link

mafredri commented Aug 24, 2022

In case anyone runs into this issue, as a work-around, it seems that removing volume_name allows host_path to work.

This issue could be fixed by disallowing both volume_name and host_path to be set since setting both doesn't make sense (a host path can't be named).

@matifali
Copy link

In case anyone runs into this issue, as a work-around, it seems that removing volume_name allows host_path to work.

This issue could be fixed by disallowing both volume_name and host_path to be set since setting both doesn't make sense (a host path can't be named).

Following this approach solved this for me.

@Junkern
Copy link
Contributor

Junkern commented Dec 22, 2022

I read the official docker docs and looked into the provider codebase and found out what the problem is.
According to https://docs.docker.com/engine/reference/run/#volume-shared-filesystems when creating a volume

The host-src can either be an absolute path or a name value. If you supply an absolute path for the host-src, Docker bind-mounts to the path you specify. If you supply a name, Docker creates a named volume by that name.

To separate this "union" type in this provider, two values got introduced: volume_name and host_path.
And @mafredri was right: having both should not be possible.

The code actually is:

volumeName := volume["volume_name"].(string)
if len(volumeName) == 0 {
  volumeName = volume["host_path"].(string)
}

which leads to the case, that as soon as the volume_name is set, the host_path does not matter. (I assume that some users think that volume_name is simply an internally used value and set both. I would do that as well, to be honest).

How to fix:

  • We could introduce a mechanisms (ConflictsWith) which checks whether both values are set and, if so it errors.
  • Or we simply assume that when host_path is set and prioritize its value
  • We move away from the two-values system and simply use a host-src, the same way as the docker documentation describes it, and simply pass the value do the docker client

I don't like option 2, and I think option 1 & 3 migh be breaking changes which would first need a warning with a new minor version and then the change with the major version.
However, I am not sure whether option 1 would really be a breaking change..

Any opinions of the people affected by this bug?

@matifali
Copy link

I would prefer option 1 with a link to docs that describe you can not use both of them at the same time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pinned r/container Relates to the container resource
Projects
None yet
Development

No branches or pull requests

4 participants