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

6

43

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.

Impute answered 23/10, 2022 at 17:55 Comment(3)
If you are using the latest version of docker desktop, notice in the release notes for 4.13.0, where they say: "By default Docker will not create the /var/run/docker.sock symlink on the host and use the docker-desktop CLI context instead." That is the possible reason why IntelliJ is not able to connect to DockerAllspice
I see, that is a possibility. Do you have a clue maybe how can I integrate it with Intellij?Impute
Please see the related discussion here youtrack.jetbrains.com/issue/IDEA-294871Scully
A
68

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.

Allspice answered 23/10, 2022 at 22:26 Comment(9)
It's also being discussed here (for further reference): github.com/testcontainers/testcontainers-java/discussions/6045. The symlink is really a "hacky" option, since nothing from /var/run should actually ever point to a file inside the HOME directory tree (which previously Docker-4.12 and earlier versions did). I suppose the Docker integration plugin of IntelliJ will soon get an update.Magnitude
Very helfpul, thank you!Foredo
A cup of tea for this gentleman, please. You are saviour! That error was driving me nuts.Terrenceterrene
wow!!! thank you very much!!! I was fighting this a whole day!!! wow!!! is there any permanent solution for this - when restarting my mac this file is deleted so I need to run this hacky option command every time.....Strongarm
As @Magnitude mentioned, we probably will need to wait until people start to update the products. Another option which I haven't tested is to export the DOCKER_HOST variable to point to the desktop-linux context, in your ~/.zshrc or ~/.bashrc - But I haven't tested it.Allspice
THIS fixed for MacOSX Docker EngineAPI URL: unix:///Users/<USER>/.docker/run/docker.sockBathhouse
You should also add: 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. Currently it happened to me that it was enabled but the background item was not added, so after toggling the option it re-added the background item and fixed the issue :pGyno
are you god? <3Wearisome
NICE! I'm newer to Linux and this has had me boggled for DAYS. On Windows, installed IntelliJ > Installed Docker > everything worked immediately. On Linux, Installed IntelliJ > Installed Docker Desktop > spend hours googling for multiple days > still no fixes, come across a bajillion different "fixes" > eventually find a single solution on a random stack overflow post with the solution. Thank you!Platinic
S
33

I'm running Docker Desktop v4.18.0 and I fixed this by

  1. going to settings in Docker Desktop
  2. click Advanced
  3. check Enable default Docker socket. Underneath this option is an explanation saying, Creates /var/run/docker. sock which some third-party clients may use to communicate with Docker Desktop.
  4. click Apply & restart and try running again

docker settings

Spry answered 17/4, 2023 at 19:44 Comment(2)
Confirming this with docker 4.19.0. Thanks!Shaw
Currently, there is a bug in Docker Desktop UI and this option is missing. Ref of the problem and quick fix: github.com/docker/for-mac/issues/7127#issuecomment-1977121701Scurvy
U
5

For some reason, after updating the macOS docker version, it doesn’t create the /var/run/docker.sock file anymore. Creating a symlink is a hacky way and not recommended.

My solution is to set the $DOCKER_HOST environment variable:

export DOCKER_HOST=unix:///Users/<USER>/.docker/run/docker.sock

or add it to .zshrc:

echo "export DOCKER_HOST=unix:///Users/<USER>/.docker/run/docker.sock" >> ~/.zshrc

or add it in the IntelliJ run configuration.

I encountered this problem with Testcontainers, which you can also fix by editing ~/.testcontainers.properties:

cat .testcontainers.properties
#Modified by Testcontainers
#Mon May 29 11:42:37 EEST 2023
docker.client.strategy=org.testcontainers.dockerclient.EnvironmentAndSystemPropertyClientProviderStrategy
testcontainers.reuse.enable=true
docker.host=unix\:///Users/<USER>/.docker/run/docker.sock

Edit documentaton:

https://www.testcontainers.org/features/configuration/

Customizing Docker host detection Testcontainers will attempt to detect the Docker environment and configure everything to work automatically.

However, sometimes customization is required. Testcontainers will respect the following environment variables:

DOCKER_HOST = unix:///var/run/docker.sock See Docker environment variables

TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE Path to Docker's socket. Used by Ryuk, Docker Compose, and a few other containers that need to perform Docker actions. Example: /var/run/docker-alt.sock

TESTCONTAINERS_HOST_OVERRIDE Docker's host on which ports are exposed. Example: docker.svc.local

Uterine answered 29/5, 2023 at 8:52 Comment(1)
This is more generic considering IJ Idea and docker extension.Unit
U
0

If you are using wsl for Windows to run docker engine, then you need to change Docker extension settings in IJ IDE to 'wsl for windows'.

If you are using Podman to run docker engine then you need to select 'Docker Desktop' option from Docker extension settings.

Unit answered 23/1 at 10:2 Comment(0)
C
-1

For Docker Desktop from version 4.17 go to Settings -> General and enable option "Open Docker Dashboard at startup" then restart Mac. This will create socket at correct path.

Chiffchaff answered 9/3, 2023 at 1:16 Comment(1)
This is incorrect. I have 4.17 and open docker dashboard on startup enabled, just had a reboot, but still no /var/run/docker.sock... Must be somewhere else!Diphtheria
R
-1

Add the following line to Environment variables of IDEA:

XDG_RUNTIME_DIR=/Users/<USER>/.docker/run/
Rosecan answered 11/4, 2023 at 20:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.