digitalocean / doctl

The official command line interface for the DigitalOcean API.
https://docs.digitalocean.com/reference/doctl/
Apache License 2.0
3.26k stars 397 forks source link

Can `dockerSocketPath` be configurable, issues when socket is in different location. #1572

Open valentincodes opened 2 months ago

valentincodes commented 2 months ago

https://github.com/digitalocean/doctl/blob/9282784517cb25d3cb6b06a4895626b173177603/internal/apps/builder/cnb.go#L36

Error: preparing build environment: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Socket location: /Users/<user>/.docker/run/docker.sock

Adya-Prasad commented 2 months ago

Can you please explain in some more detail!

valentincodes commented 2 months ago

When running

doctl app dev build

I get ✔ fetching app details ✔ loading config from app ▸ current app dev workspace: ✔ preparing app dev environment Error: preparing build environment: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Docker is running but location is /Users/<user>/.docker/run/docker.sock

pedro-tl commented 1 week ago

I am having the same issue. I've had it before with different projects due to the way Docker Desktop sets things up nowadays.

Creating a symlink to the local user socket solves it: sudo ln -s /home/youruser/.docker/desktop/docker.sock /var/run/docker.sock

I can see the source code evals symlinks in the hardcoded path, unsure if the Docker Desktop installation was supposed to create it and failed, but it does work when the symlink is manually created.

pedro-tl commented 1 week ago

It seems the command still fails, albeit much further down the line now. I can see my app's build stage being completed, and the following error comes after that:

    ╭──────────── container image ───────────╼
    │  › creating app container image
    │ ERROR: failed to initialize docker client: failed to connect to docker socket: dial unix /var/run/docker.sock: connect: connection refused
    │ 
    │ command exited with code 1
    │  ✘ image creation failed
Error: command exited with a non-zero status code

I have tried with both the symlink and by prepending DOCKER_HOST to the command, like so: DOCKER_HOST=unix:///home/youruser/.docker/desktop/docker.sock doctl app dev build. Either combination of workarounds always results in the mentioned output.

This issue in buildpacks seems to hint that the export container fails to access the Docker daemon, due to non standard daemon socket location. One workaround in there is to run pack with the --docker-host=inherit flag, but there's no way for me to inject that flag into doctl's chain to test it. The issue has been open since Dec 1, 2021, so don't know if it is preferable to wait for it to be closed on buildpack's side, or detect this scenario and inject the flag on doctl's side.