Could not find a valid Docker environment
Overview
After updating my Mac and finding that Docker was not working properly, I had to reinstall it. However, I encountered an error where the container was not running properly when running tests.
It turned out that there was an issue with the /var/run/docker.sock
not being properly configured. Here, I will share the solution to resolve this issue.
Description
This problem occurs in Docker desktop version 4.13.0
.
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/)
You can check the current Docker context using docker context ls
, which will display something like this:
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
To fix the issue, either set the default context or connect to unix:///Users/<USER>/.docker/run/docker.sock
.
Solution
Try running the following command to switch to the default context and check if Docker works properly:
docker context use default
If the issue persists, you can manually create a symbolic link to resolve it with the following command:
sudo ln -svf /Users/<USER>/.docker/run/docker.sock /var/run/docker.sock