colima icon indicating copy to clipboard operation
colima copied to clipboard

Colima, buildx and docker daemon setup

Open debo opened this issue 8 months ago • 8 comments

Hello everyone, this is probably more of a "how to configure Colima properly" rather than an actual issue or maybe it's an issue I am not sure, it is sort of subjective on this one I would say.

Like many people I made the switch to Colima from Docker Desktop and love Colima to pieces but, there is a little thing that is really driving me nuts and I am not sure how to go about it so that it works in a seamless way. The problem has to do with how Colima manages docker contexts and buildx contexts, if I run docker context ls I get the following:

~ docker context ls
NAME       DESCRIPTION                               DOCKER ENDPOINT                                             ERROR
colima *   colima                                    unix:///Users/marco.debortoli/.colima/default/docker.sock
default    Current DOCKER_HOST based configuration   unix:///var/run/docker.sock

All good, nice and clean as I expect it to be. But when I run docker buildx ls I get the following instead:

docker buildx ls
NAME/NODE    DRIVER/ENDPOINT   STATUS    BUILDKIT   PLATFORMS
colima*      docker
 \_ colima    \_ colima        running   v0.20.0    linux/arm64
default                        error

Cannot load builder default: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Which again is somehow right because nothing is running on unix:///var/run/docker.sock but it is really gets to my head to see that error. I know that a way to make if work is to set the DOCKER_HOST variable but if I do that then this is what I get running docekr context ls again:

docker context ls
NAME        DESCRIPTION                               DOCKER ENDPOINT                                             ERROR
colima      colima                                    unix:///Users/marco.debortoli/.colima/default/docker.sock
default *   Current DOCKER_HOST based configuration   unix:///Users/marco.debortoli/.colima/default/docker.sock
Warning: DOCKER_HOST environment variable overrides the active context. To use a context, either set the global --context flag, or unset DOCKER_HOST environment variable.

So basically I just move the error to a warning in another place and it also doesn't feel clean/right.

My question then is, what's a clean way to go about this and having Colima work in these scenarios without errors or warning? Thank you for any insight you can provide.

debo avatar Apr 28 '25 08:04 debo

I recently set this in my ~/.zshrc to make sure :

export DOCKER_HOST=$(docker context inspect -f '{{ .Endpoints.docker.Host }}')

And this command works for me:

docker buildx ls
NAME/NODE     DRIVER/ENDPOINT   STATUS    BUILDKIT   PLATFORMS
colima        docker
 \_ colima     \_ colima        running   v0.17.3    linux/amd64 (+2), linux/arm64, linux/386
default*      docker
 \_ default    \_ default       running   v0.17.3    linux/amd64 (+2), linux/arm64, linux/386

Source: https://github.com/wagoodman/dive/pull/565#issue-2821757942.

webdevotion avatar May 22 '25 11:05 webdevotion

The problem with that approach is that you then get a warning when running:

~ docker context ls
NAME        DESCRIPTION                               DOCKER ENDPOINT                                             ERROR
colima      colima                                    unix:///Users/marco.debortoli/.colima/default/docker.sock
default *   Current DOCKER_HOST based configuration   unix:///Users/marco.debortoli/.colima/default/docker.sock
Warning: DOCKER_HOST environment variable overrides the active context. To use a context, either set the global --context flag, or unset DOCKER_HOST environment variable.

debo avatar May 29 '25 11:05 debo

I believe the issue lies is that your default context points to unix:///var/run/docker.sock which iirc is the socket for Docker. Colima creates docker.sock under /Users/<youruser>/.colima/docker.sock. So for me it was enough to actually symlink this socket to /var/run/docker.sock using

sudo ln -s /Users/<youruser>/.colima/docker.sock /var/run/docker.sock

mateocolina avatar Jul 29 '25 12:07 mateocolina

It is more of a warning/info than an error that you can safely ignore.

If you feel uncomfortable with it, you can link to the default docker socket as mentioned here https://github.com/abiosoft/colima/issues/1309#issuecomment-3132174937.

abiosoft avatar Jul 31 '25 14:07 abiosoft

I believe the issue lies is that your default context points to unix:///var/run/docker.sock which iirc is the socket for Docker. Colima creates docker.sock under /Users/<youruser>/.colima/docker.sock. So for me it was enough to actually symlink this socket to /var/run/docker.sock using

sudo ln -s /Users/<youruser>/.colima/docker.sock /var/run/docker.sock

Well yes, and that's always true. I believe it's hardcoded somewhere even in Colima as far as I remember. I think I read somewhere that symlink the socket could lead to other issues down the road, that's why I didn't do it... I think.

debo avatar Aug 25 '25 11:08 debo

It is more of a warning/info than an error that you can safely ignore.

If you feel uncomfortable with it, you can link to the default docker socket as mentioned here #1309 (comment).

Yes I saw but, as I mentioned I read somewhere it is not recommended. I wonder if it could be worth to have a check on where that socket is even used or present and maybe behave accordingly but at the same time I appreciate it might not be a priority.

debo avatar Aug 25 '25 11:08 debo

I just added the following lines to my .zshrc file to docker buildx ls output without an error or warning:

# Colima - Docker for Mac alternative
# Set the Docker host to use Colima's socket
export DOCKER_HOST="unix://$HOME/.colima/docker/docker.sock"

I'm using at the point of writing the following version of docker-buildx plugin:

> brew info docker-buildx
==> docker-buildx: stable 0.29.1 (bottled), HEAD
Docker CLI plugin for extended build capabilities with BuildKit
https://docs.docker.com/buildx/working-with-buildx/
Installed
/opt/homebrew/Cellar/docker-buildx/0.29.1 (41 files, 66.5MB) *
  Poured from bottle using the formulae.brew.sh API on 2025-11-13 at 00:22:06
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/d/docker-buildx.rb
License: Apache-2.0
==> Dependencies
Build: go ✘
==> Options
--HEAD
        Install HEAD version
==> Caveats
docker-buildx is a Docker plugin. For Docker to find the plugin, add "cliPluginsExtraDirs" to ~/.docker/config.json:
  "cliPluginsExtraDirs": [
      "/opt/homebrew/lib/docker/cli-plugins"
  ]
==> Analytics
install: 3,685 (30 days), 18,552 (90 days), 65,707 (365 days)
install-on-request: 3,681 (30 days), 18,537 (90 days), 65,626 (365 days)
build-error: 1 (30 days)
> cat ~/.docker/config.json

{
        "auths": {
                "127.0.0.1": { },
        },
        "cliPluginsExtraDirs": [
                "/opt/homebrew/lib/docker/cli-plugins"
        ],
        "currentContext": "colima-docker",
        "features": {
                "buildkit": "true",
                "containerd": "true",
                "hooks": "true"
        },
        "plugins": {
                "-x-cli-hints": {
                        "enabled": "true"
                },
                "debug": {
                        "hooks": "exec"
                },
                "scout": {
                        "hooks": "pull,buildx build"
                }
        }
}

I had some issues at first, before the above approach correctly worked, because the default builder always showed an error message without a socket URL/path like unix://....

Here it gets a bit unsharp, because I write down from my memories without verifying my knowledge again, but I hope that my knowledge helps the next person to identify similar issues that are somehow awkward.

What I recognized is that when there is a shell env variable DOCKER_HOST with a value set up, then docker buildx ls uses it but doesn't show an error message that includes a socket URL/path. -> That indicates that the value of DOCKER_HOST is not correct or the socket is not implementing the Docker API.

When I created a symlink via ln -s like ln -s $HOME/.colima/docker/docker.sock /var/run/docker.sock then docker buildx ls showed me still an issue with the default builder, with an error message that didn't include the URL/path to the socket. -> I removed the /var/run/docker.sock file/symlink.

  1. Then I stopped all Colima profiles via:
    1. colima stop (profile: default which is runtime: incus) and
    2. colima stop --profile docker (profile docker which is runtime docker).
  2. Ensured that .zshrc has not a export DOCKER_HOST="..." defined, which sets up the ENV variable.
  3. Opened a new “terminal-tab”/“zsh-session”:
    1. Then I started all Colima profiles via:
      1. colima start (profile: default which is runtime: incus) and
      2. colima start --profile docker (profile docker which is runtime docker).
    2. docker buildx ls to check if I still have an error with the default builder, which should be, but now we should see an error message with the socket URL/path included.
    3. export DOCKER_HOST="unix://$HOME/.colima/docker/docker.sock"
    4. docker buildx ls to check if I still have an error with the default builder, which shouldn't be anymore; now we shouldn't see any error or warning message; the default builder should be shown without an error.
    5. Then I added export DOCKER_HOST="unix://$HOME/.colima/docker/docker.sock" to my .zshrc file to resolve the issue permanently.
> docker buildx ls

NAME/NODE           DRIVER/ENDPOINT     STATUS    BUILDKIT   PLATFORMS
colima-docker       docker                                   
 \_ colima-docker    \_ colima-docker   running   v0.24.0    linux/amd64 (+2), linux/arm64, linux/386
default*            docker                                   
 \_ default          \_ default         running   v0.24.0    linux/amd64 (+2), linux/arm64, linux/386

tobiashochguertel avatar Nov 13 '25 00:11 tobiashochguertel

Sure, but that doesn't solve the other issue of docker context ls showing the warning instead.

debo avatar Nov 13 '25 01:11 debo