I am attempting to run 3 Docker images, MySQL, Redis and a project of mine on Bash for Windows (WSL).
To do that I have to connect to the Docker engine running on Windows, specifically on tcp://locahost:2375
. I have appended the following line to .bashrc
:
export DOCKER_HOST=tcp://127.0.0.1:2375
I can successfully run docker
commands like docker ps
or docker run hello-world
but whenever I cd
into my project directory and run
sudo docker-compose up --build
to load the images and spin up the containers I get an error:
ERROR: Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running?
If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
I know that if I use the -H
argument I can supply the address but I'd rather find a more permanent solution. For some reason docker-compose
seems to ignore the DOCKER_HOST
environmental variable and I can't figure out why..
Your problem is sudo
. It's a totally different program than your shell and doesn't transfer the exported environment unless you specifically tell it to. You can either add the following line in your /etc/sudoers
(or /etc/sudoers.d/docker
):
Defaults env_keep += DOCKER_HOST
Or you can just pass it directly to the command line:
sudo DOCKER_HOST=$DOCKER_HOST docker-compose up --build