Search code examples
dockermacosintellij-ideadocker-composedocker-desktop

Docker socket is not found while using Intellij IDEA and Docker desktop on MacOS


I downloaded Docker using Docker Desktop for Apple M1 chips. I can run containers, the integration with VsCode works okay but I can't integrate it with Intellij IDEA Ultimate. It keeps giving this error. enter image description here

But I can run my containers and create images from the terminal, I can also see the containers and images in Docker Desktop too. What could be the reason behind this? I also tried to check whether var/run/docker.sock is existing and it really isn't, there is no such file as that.

I also tried the same steps on my second computer and the exact same thing happened. Steps to reproduce: 1- Download Intellij IDEA Ultimate, open a repo that uses docker 2- Download Docker Desktop for Mac M1 3- Try to add Docker service to Intellij

I didn't do anything else because I think Docker Desktop is enough to configure everything on Mac. I am trying to run an FT on intellij and I get the error

[main] ERROR o.t.d.DockerClientProviderStrategy - Could not find a valid Docker environment. Please check configuration. Attempted configurations were:
[main] ERROR o.t.d.DockerClientProviderStrategy -     UnixSocketClientProviderStrategy: failed with exception InvalidConfigurationException (Could not find unix domain socket). Root cause NoSuchFileException (/var/run/docker.sock)
[main] ERROR o.t.d.DockerClientProviderStrategy -     DockerMachineClientProviderStrategy: failed with exception ShellCommandException (Exception when executing docker-machine status ). Root cause InvalidExitValueException (Unexpected exit value: 1, allowed exit values: [0], executed command [docker-machine, status, ], output was 122 bytes:
Docker machine "" does not exist. Use "docker-machine ls" to list machines. Use "docker-machine create" to add a new one.)
[main] ERROR o.t.d.DockerClientProviderStrategy - As no valid configuration was found, execution cannot continue

I've been trying everything for the last 2 days but I can't seem to find a solution.


Solution

  • EDITED 2022-10-31

    Release notes for Docker Desktop (4.13.1) (and following versions), states that, there is no need to create the symlink anymore, citing notes:

    Added back the /var/run/docker.sock symlink on Mac by default, to increase compatibility with tooling like tilt and docker-py. Fixes docker/for-mac#6529.

    The official fix now is to UPGRADE your Docker Desktop installation.

    For the Docker Desktop (4.13.0) version:

    By default Docker will not create the /var/run/docker.sock symlink on the host and use the docker-desktop CLI context instead. (see: https://docs.docker.com/desktop/release-notes/)

    That will prevent IntelliJ from finding Docker using the default context.

    You can see the current contexts in your machine by running docker context ls, which should produce an output like:

    NAME                TYPE    DESCRIPTION                               DOCKER ENDPOINT                                KUBERNETES ENDPOINT                                 ORCHESTRATOR
    default             moby    Current DOCKER_HOST based configuration   unix:///var/run/docker.sock                    https://kubernetes.docker.internal:6443 (default)   swarm
    desktop-linux *     moby                                              unix:///Users/<USER>/.docker/run/docker.sock
    
    

    As a workaround that will allow IntelliJ to connect to Docker you can use the TCP Socket checkbox and put in the Engine API URL the value that appears under DOCKER ENDPOINT in the active context.

    The case for this example will be: unix:///Users/<USER>/.docker/run/docker.sock

    Then IntelliJ will be able to connect to Docker Desktop.

    EDITED 2023-07-17

    If the option in "Settings > Advanced > Allow the default Docker socket to be used" is already enabled and the socket is not available try disabling it and re-enabling it.

    **Hacky option**

    Another way to make IntelliJ (and other components that rely on the default config) to find Docker will be to manually create a symlink to the new DOCKER ENDPOINT by running:

    sudo ln -svf /Users/<USER>/.docker/run/docker.sock /var/run/docker.sock
    

    In that way all the components looking for Docker under /var/run/docker.sock will find it.