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

Zarf does not respect docker contexts #2674

Open
mjnagel opened this issue Jun 27, 2024 · 6 comments
Open

Zarf does not respect docker contexts #2674

mjnagel opened this issue Jun 27, 2024 · 6 comments

Comments

@mjnagel
Copy link
Contributor

mjnagel commented Jun 27, 2024

Environment

Device and OS: MBP, macOS
App version: v0.34.0
Kubernetes distro being used: k3d (not relevant here)
Other:

Steps to reproduce

I'm encounter an issue on my mac when I attempt to use the local docker fallback for a local image. Relevant piece of this is that my docker socket is provided by colima and is not the default path.

  1. Make a zarf.yaml that references an image that does not exist remotely but is local.
  2. Attempt to create this package
  3. Zarf will fallback to pulling from the local docker.

Expected result

Zarf respects my docker context/uses it (note my active context is colima here):

docker context ls
NAME       DESCRIPTION                               DOCKER ENDPOINT                                     ERROR
colima *   colima                                    unix:///Users/mjnagel/.colima/default/docker.sock   
cooper     Remote cooper Docker host                 ssh://cooper                                        
default    Current DOCKER_HOST based configuration   unix:///var/run/docker.sock                         

Actual Result

Zarf only considers the DOCKER_HOST environment variable:

          ERROR:  Failed to create package: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the                                                                                                  
                  docker daemon running?                                                                                                                                                                                

Severity/Priority

Low, by setting DOCKER_HOST to my active context I can make this work, although I don't believe I've been able to make docker-over-ssh work with the DOCKER_HOST env/zarf.

@AustinAbro321
Copy link
Contributor

Thanks for the issue @mjnagel!

While, I'm not opposed to supporting this docker context's are more a feature of the CLI than the daemon. If we wanted to solve this we would have to get the url of the docker sock for that context.
To do this we can either:

  • Figure out how to call the docker CLI from go using https://github.com/docker/cli. This can be trickier than it first seems, but if there is an easy way to get the host from calls to the cli package this would be best.
  • Follow some of the docker logic summarized below to get the current context. Using the current context we would than have to look at the path ~/.docker/contexts/meta/33341cc9809c9410f1149a11fc4a79a53562069c7ff0c652fa18b8c83e3ec34b/meta.json and open that file to get the hostname of the docker sock
2. The "DOCKER_CONTEXT" environment variable.
3. The current context as configured through the in "currentContext"
field in the CLI configuration file ("~/.docker/config.json").

@mjnagel
Copy link
Contributor Author

mjnagel commented Aug 27, 2024

@AustinAbro321 interesting mention of CLI vs daemon. I may have to validate and test out a few other tools, but I think in my experience docker contexts are typically honored by other tools. k3d is the one that immediately comes to mind - clusters will be spun up on your active docker context rather than looking at the default socket only/DOCKER_HOST. From a quick skim of their code it seems like they are leveraging the go docker cli like what you mentioned in option 1.

Definitely not familiar with complexity of this on the zarf side, but it would be a pretty nice QoL improvement - especially as mentioned in my case trying to use Docker over SSH. This works for the rest of my operations (k3d, docker builds, etc) but fails with zarf's local docker fallback. If there were any workarounds this might not be so bad but I'm unaware of a way to handle this outside of Zarf itself respecting my context.

@mjnagel
Copy link
Contributor Author

mjnagel commented Aug 27, 2024

Re-running through previous testing steps, I am able to set my docker host this way to point to my docker over ssh host:

export DOCKER_HOST=ssh://mjnagel@1.2.3.4

Docker CLI commands, k3d commands, etc all work. However when I try to use zarf expecting the local docker fallback to work I encounter this issue:

 WARNING  Falling back to local 'docker', failed to find the manifest on a remote: GET
          https://index.docker.io/v2/mjnagel/test123/manifests/latest: MANIFEST_UNKNOWN: manifest
          unknown; unknown tag=latest
     ERROR:  failed to create package: error during connect: Get "http://mjnagel%401.2.3.4/v1.24/images/docker.io/mjnagel/test123:latest/json": dial tcp: lookup mjnagel@1.2.3.4: no such host

Perhaps the more troublesome problem here is that Zarf does not support docker over SSH for this local fallback - even if you put aside the context issue.

@ericwyles
Copy link

I have ran into this too and if zarf worked with docker over SSH (even if just by setting DOCKER_HOST) that would be great. I like to use docker over ssh to a linux machine to test some amd64 only stuff from my arm64 mac.

@AustinAbro321
Copy link
Contributor

@mjnagel Could you make a separate issue for supporting docker over SSH

@mjnagel
Copy link
Contributor Author

mjnagel commented Aug 29, 2024

@AustinAbro321 done, #2943

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Triage
Development

No branches or pull requests

3 participants