moby: Trying to connect to Docker API for shell commands throws error

The issue: When running any Docker command, the error below is printed, and most commands don’t even run

Output of docker version:

Client:
 Version:      1.11.0
 API version:  1.23
 Go version:   go1.5.4
 Git commit:   4dc5990
 Built:        Wed Apr 13 18:13:28 2016
 OS/Arch:      windows/amd64
An error occurred trying to connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.23/version: open //./pipe/docker_engine: The system cannot find the file specified.

Output of docker info:

An error occurred trying to connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.23/info: open //./pipe/docker_engine: The system cannot find the file specified.

Additional environment details (AWS, VirtualBox, physical, etc.): I’m in Windows 10 with Toolbox 1.11.0 with Kitematic installed

Steps to reproduce the issue:

  1. Install Docker Toolbox
  2. Run any docker command?

Describe the results you received: The exact error listed in docker info here, and most commands such as docker ps don’t work

Additional information you deem important (e.g. issue happens only occasionally): This message gets pasted to the end of any Docker command I run, and only certain commands even remotely work

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 50
  • Comments: 41 (13 by maintainers)

Most upvoted comments

This is likely due to either the Virtual Machine not being started (try docker-machine start default), or the environment variables not being set in your shell (docker-machine env default should print the instructions for doing so). However, this should be reported in the docker-toolbox issue tracker, or check if there’s an existing issue; https://github.com/docker/toolbox/issues?q=is%3Aissue+“trying+to+connect”+sort%3Acomments-desc+is%3Aopen

You may be interested in the Docker for Windows beta, which resolves most of these issues; https://blog.docker.com/2016/03/docker-for-mac-windows-beta/. You can register for that beta through https://beta.docker.com.

I had the same issue after I rebooted Windows once (before reboot docker worked fine). The advice to follow docker-machine env default instructions worked for me.

This is how it was:

Maksym@MaksymPC MINGW64 ~
$ docker ps
An error occurred trying to connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.23/containers/json: open //./pipe/docker_engine: The system cannot find the file specified.

Maksym@MaksymPC MINGW64 ~
$ docker-machine env default
Error checking TLS connection: Error checking and/or regenerating the certs: There was an error validating certificates for host "192.168.99.100:2376": tls: DialWithDialer timed out
You can attempt to regenerate them using 'docker-machine regenerate-certs [name]'.
Be advised that this will trigger a Docker daemon restart which will stop running containers.

Maksym@MaksymPC MINGW64 ~
$ docker-machine regenerate-certs
Regenerate TLS machine certs?  Warning: this is irreversible. (y/n): y
Regenerating TLS certificates
Waiting for SSH to be available...
Detecting the provisioner...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...

Maksym@MaksymPC MINGW64 ~
$ docker ps
An error occurred trying to connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.23/containers/json: open //./pipe/docker_engine: The system cannot find the file specified.

Maksym@MaksymPC MINGW64 ~
$ docker-machine env default
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="C:\Users\Maksym\.docker\machine\machines\default"
export DOCKER_MACHINE_NAME="default"
# Run this command to configure your shell:
# eval $("C:\Program Files\Docker Toolbox\docker-machine.exe" env default)

Maksym@MaksymPC MINGW64 ~
$ eval $("C:\Program Files\Docker Toolbox\docker-machine.exe" env default)

Maksym@MaksymPC MINGW64 ~
$ docker ps
CONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS                         PORTS                  NAMES

i.e. @FOR /f "tokens=*" %i IN ('docker-machine.exe env --shell cmd') DO @%i

Same issue but gone when changed from powershell to cmd but now it’s stuck at docker run command:

c:\_projects\docker>docker run --rm -i -t -p 80:80 nginx
docker: An error occurred trying to connect: Post http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.23/containers/create: open //./pipe/docker_engine: The system cannot find the file specified..
See 'docker run --help'.

c:\_projects\docker>docker-machine start default
Starting "default"...
Machine "default" is already running.

c:\_projects\docker>docker-machine env --shell cmd default
SET DOCKER_TLS_VERIFY=1
SET DOCKER_HOST=tcp://192.168.99.102:2376
SET DOCKER_CERT_PATH=C:\Users\DBashyal\.docker\machine\machines\default
SET DOCKER_MACHINE_NAME=default
REM Run this command to configure your shell:
REM     @FOR /f "tokens=*" %i IN ('docker-machine env --shell cmd default') DO @%i

c:\_projects\docker>@FOR /f "tokens=*" %i IN ('docker-machine env --shell cmd default') DO @%i

c:\_projects\docker>docker run --rm -i -t -p 80:80 nginx

The machine is running, I’ve even got containers running in Kitematic, its just that the shell commands won’t work. I’m fairly sure this is a Docker issue not something with Toolbox

This is what I did… and worked fine

$ docker-machine env default
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="C:\Users\praveen.k.patidar\.docker\machine\machines\default"
export DOCKER_MACHINE_NAME="default"
# Run this command to configure your shell:
# eval $("C:\installs\Docker\docker-machine.exe" env default)

praveen.k.patidar@CPX-HQKUP9187JJ MINGW64 ~
$ eval $("C:\installs\Docker\docker-machine.exe" env default)

If it’s running, then I suspect the environment variables aren’t set; did you try docker-machine env default, and followed the instructions?

You have to run this: @FOR /f “tokens=*” %i IN (‘docker-machine env docker1’) DO @%i

I got the same error when I tried to launch docker ps, but the rest of the commands work properly. After some time we found that there was any active docker-machine.

If you launch docker-machine ls command and you see that they are running (I have 2) but any of them is the active, then, you must launch the next one to activate the default machine.

eval $(docker-machine env default)

This fixes the issue.

You set the environment variables following the instructions of docker-machine env --shell cmd?

I just ran into this issue. A google search led me to this page, and I ran the commands in docker-machine env default and things worked out well. This was the first time using the product following the quicksart directions here. It creates friction when starting with the product, and it would be nice if there were a more user friendly error message explaining what to do.

👍 Glad to hear it’s working now all

It was cmd, but it was probably an earlier version of docker tools too. The latest doesn’t output the quotes anymore. Just wanted to mention the source of that error, in case anyone sees it again.

C:\acme\Aphrodite\gits\cfg-compose>docker-machine env
SET DOCKER_TLS_VERIFY=1
SET DOCKER_HOST=tcp://192.168.99.100:2376
SET DOCKER_CERT_PATH=C:\Users\Install\.docker\machine\machines\default
SET DOCKER_MACHINE_NAME=default
REM Run this command to configure your shell:
REM     @FOR /f "tokens=*" %i IN ('docker-machine env') DO @%i

To avoid runin that command each time try on your windows git bash CLI: echo 'eval $("C:\Program Files\Docker Toolbox\docker-machine.exe" env default)' >> .bash_profile This will append that string at the end of .bash_profile. Open a new instance to changes take effect.

I got the same issue then I realized about the invoke-expression missing at the end of the command:

docker-machine env --shell powershell default | Invoke-Expression

Without the invoke, the variables only gonna be printed in your shell.

Hope this can help anyone else.