2

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..

Community
  • 1
  • 1
dimlucas
  • 5,040
  • 7
  • 37
  • 54

2 Answers2

8

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 
alindobre
  • 456
  • 3
  • 6
0

By set DOCKER_HOST you tell for every run of docker in command line to use http api, instead of default - socket on localhost.

By default http api is not turned on

$ sudo cat /lib/systemd/system/docker.service | grep ExecStart
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

you can add -H tcp://127.0.0.1:2375 for tern on http api on localhost but usually you want to tern on api for remote servers by -H tcp://0.0.0.0:2375 (do it only with proper firewall)

so you need to change in /lib/systemd/system/docker.service to next line

ExecStart=/usr/bin/dockerd -H fd:// -H tcp://127.0.0.1:2375 --containerd=/run/containerd/containerd.sock
Ryabchenko Alexander
  • 10,057
  • 7
  • 56
  • 88