terraform-provider-docker icon indicating copy to clipboard operation
terraform-provider-docker copied to clipboard

Support for Docker contexts

Open voroninman opened this issue 1 year ago • 4 comments

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

Look up the Docker host from Docker Context instead of DOCKER_HOST or the hardcoded /var/run/docker.sock. A nice bonus would be to select a context with an argument to the provider.

Potential Terraform Configuration

provider "docker" {
  context = "development"
}

In my particular case I want to the provider to work with https://github.com/abiosoft/colima. For a workaround I do export DOCKER_HOST=$(docker context inspect | jq -r '.[0].Endpoints.docker.Host').

voroninman avatar Apr 07 '23 08:04 voroninman

Yes, it should make life easy. Currently, I am using custom logic to extract the host from the selected docker context.

matifali avatar May 26 '23 05:05 matifali

Does anyone know if there is a Docker API call with the Docker context information?

I've got a fork with a fix that could work but it just relies on testing the presence of a couple possible docker.sock paths. So not very determinable.

nathanblair avatar May 26 '23 10:05 nathanblair

docker context reads from the local ~/.docker/contexts/ directory so it does not have an API. also, this is different for each of the logged-in users.

matifali avatar Jun 07 '23 07:06 matifali

This could potentially solve https://github.com/kreuzwerker/terraform-provider-docker/issues/262 as well

cryptiklemur avatar Feb 24 '24 21:02 cryptiklemur