Docker for Windows not working

2019-01-30 02:22发布

I've installed Docker toolbox now and I get the error for everything:

Get http://127.0.0.1:2375/v1.20/version: dial tcp 127.0.0.1:2375: ConnectExtcp: No connection could be made because the target machine actively refused it..
* Are you trying to connect to a TLS-enabled daemon without TLS?
* Is your docker daemon up and running?

docker version output:

Client:
 Version:      1.8.1
 API version:  1.20
 Go version:   go1.4.2
 Git commit:   d12ea79
 Built:        Thu Aug 13 02:49:29 UTC 2015
 OS/Arch:      windows/amd64
Get http://127.0.0.1:2375/v1.20/version: dial tcp 127.0.0.1:2375: ConnectEx tcp: No connection could be made because the target machine actively refused it..
* Are you trying to connect to a TLS-enabled daemon without TLS?
* Is your docker daemon up and running?

But the VM is running under VirtualBox. I have searched everywhere but can't find a solution.

UPDATE1: I'm using Windows 8.1 and also tried to start through Kinematic also.

UPDATE2: Everything worked like charm when I tried Virtualbox Test Build 5.0.3 or later. You can download here: https://www.virtualbox.org/wiki/Testbuilds

标签: docker
17条回答
ら.Afraid
2楼-- · 2019-01-30 02:24

Just run:

"C:\Program Files\Docker Toolbox\docker-machine" ls

get the machine name, and then run:

"C:\Program Files\Docker Toolbox\docker-machine" env <MACHINE_NAME_HERE> --shell=[cmd|powershell]

and you should get something like this:

"C:\Program Files\Docker Toolbox\docker-machine" env default --shell=cmd
set DOCKER_TLS_VERIFY=1
set DOCKER_HOST=tcp://192.X.X.X:2376
set DOCKER_CERT_PATH=C:\Users\X\.docker\machine\machines\default
set DOCKER_MACHINE_NAME=default
# Run this command to configure your shell:
# copy and paste the above values into your command prompt

I also get an error open C:\Users\X\.docker\machine\machines\default\server.pem: The system cannot find the file specified. and solved it by upgrading my VirtualBox to version 5.0.3 (from their nightly builds)

Long version:

I got the same problem and after and the "Using Docker from Windows Command Line Prompt (cmd.exe)" section from the installation manual put me in the right direction

Basically, the way docker works is that the "docker " commands are passed to a docker service (running on port 2375). As you are running the docker from windows host, the service actually runs on the linux host created by docker (you can see it by opening the virtualbox ui).

The usual flow is the following:

  1. default machine is created
  2. the starter (kinamatic / "Docker Quickstart Terminal" / cmd) of the machine waits for the machine to boot, gets it's IP address and sets the linux ip:port as the service address (instead of 127.0.0.1:2375) in few enviremnt/powershell variables
  3. from this point all docker ... commands are send to the linux host and everything works almost as native linux

The problem is that there is some issue with the machine setup (my guess the new virtual box but I am not sure and have the time to dig into it). You can see that by runnung the ls command and notice that (at least in my case) the state of the machine is "timeout" and there is no url, unlike the output shown in the manual.

This causes the enviorment values not to be set and the docker ... commands to fail.

Apart from running the command, you can also start the Docker Quickstart Terminal that does the same thing but with sh shell

Regarding the certificate error, I tried to regenrate the certificates from within the virtual machine using:

/usr/local/bin/generate_cert --overwrite --host=default,127.0.0.1,10.0.2.15,192.168.99.100 --ca=/var/lib/boot2docker/tls/ca.pem --ca-key=/var/lib/boot2docker/tls/cakey.pem --cert=/var/lib/boot2docker/tls/server.pem --key=/var/lib/boot2docker/tls/serverkey.pem

I got "protocol error"s when tried to copy the certificate to the host machine, which reminded me an old virtualbox shared folders bug, so this may not be a problem with docker but with virtualbox - I upgraded to the latest nightly version (5.0.3-102224), regenerated the default image and that seems to solve it. As windows 10 is not officially supported yet neither by docker nor by virtualbox, I am not sure if this is the same thing that causes you to get the certificate error, In any case can try to copy the certificates from the virtual machine (you have the paths in code block) to your local user directory (it is mapped to /c/Users/X/ in the virtual machine)

查看更多
Bombasti
3楼-- · 2019-01-30 02:24

Just recreate the default machine, and then run

docker-machine env default

It works for me.

查看更多
一夜七次
4楼-- · 2019-01-30 02:30

This has happened a few times for me on Windows 10 with VirtualBox 5.0.14.

It seems to be related with not shutting down VirtualBox correctly (I believe) - for example, a power cut!

  1. Shutdown the Docker VM

  2. Close Kitematic

  3. Start the Docker Quickstart Terminal

  4. Type in the terminal:

docker-machine.exe -D ls

  1. Start Kitematic. VM's show up now.

If that does not work, try 1-3 again and this time try to regenerate certs. Then do step 4.

One thing that is odd, is that in the terminal docker images does not list them but says it cannot connect to 127.0.0.1:2375 (but docker-machine ls shows the default machine running on 192.168.99.100:2376).

查看更多
乱世女痞
5楼-- · 2019-01-30 02:32

Had the same issue as you showed and Just fixed it a few hours ago.

All need to do is disable Hyper-V. Run a command prompt with administrator rights and run the following command:

bcdedit /set hypervisorlaunchtype off

Restart your PC, open virtualbox and delete default vm after relaunch, go back to docker quickstart terminal and put the following in command:

docker run hello-world

and you're done! Hope it solves your problem

查看更多
Rolldiameter
6楼-- · 2019-01-30 02:34

this works for me

1) start the command line tool first and get the machine ip address by running

docker-machine ls command

2) Re-generate certs docker-machine regenerate-certs

3) Set the evn variables manually in my case the location of certs was different

set DOCKER_TLS_VERIFY=1

set DOCKER_HOST=tcp://machine_IP:2376

set DOCKER_CERT_PATH=C:\Users\X.docker\machine\certs

set DOCKER_MACHINE_NAME=default

Now run docker version

Here is the output in my case

Client: Version: 1.8.1 API version: 1.20 Go version: go1.4.2 Git commit: d12ea79 Built: Thu Aug 13 02:49:29 UTC 2015 OS/Arch: windows/amd64

Server: Version: 1.8.1 API version: 1.20 Go version: go1.4.2 Git commit: d12ea79 Built: Thu Aug 13 02:49:29 UTC 2015 OS/Arch: linux/amd64

查看更多
我命由我不由天
7楼-- · 2019-01-30 02:34

The Docker Toolbox (in 1.8.x) installation configure by default your Docker Daemon to use secure connection via the TLS protocol (version 1.8).

If you were using an older version of the daemon that wasn't secured that means at least two things : - the port number changed from 2375 to 2376 - your daemon client need to present a certificat to communicate with you docker engine/server.

So the reply of sandiindia indicates the environment variables that precise to the docker client the good configuration to connect to the docker server/engine:

#You're using a TLS secured daemon : 
set DOCKER_TLS_VERIFY=1

# Precise the Docker Host IP and port, the TLS default is 2376
set DOCKER_HOST=tcp://*<docker_host_IP>*:2376

# The paths to the certificate and client key needed to authenticate to the daemon
# You should have 3 files in this directory : ca.pem, cert.pem and key.pem 
# In my case the default path looks like : 
set DOCKER_CERT_PATH=C:\Users\*<username>*\.docker\machine\machines\default

#the name of your Docker Host VM : 
set DOCKER_MACHINE_NAME=default

The docker documentation about TLS configuration : https://docs.docker.com/articles/https/

I hope it helps ;)

查看更多
登录 后发表回答