英文原帖

Running Docker from Windows CMD prompt

https://medium.com/@neil.avery_68603/running-docker-from-windows-cmd-prompt-6540daebedad

#### 打开CMD窗口,尝试运行docker命令,检查docker环境是否可用 `docker run hello-world`

C:\Users\NovakZheng>docker run hello-world

docker: error during connect: Post http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.31/c
ontainers/create: open //./pipe/docker_engine: The system cannot find the file s
pecified. In the default daemon configuration on Windows, the docker client must
 be run elevated to connect. This error may also indicate that the docker daemon
 is not running.
See 'docker run --help'.

尝试其它docker命令, `docker ps`

C:\Users\NovakZheng>docker ps

error during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.31/containers
/json: open //./pipe/docker_engine: The system cannot find the file specified. I
n the default daemon configuration on Windows, the docker client must be run ele
vated to connect. This error may also indicate that the docker daemon is not run
ning.

用指令建立docker环境 docker-machine env

C:\Users\NovakZheng>docker-machine env default

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

再运行上文中REM后面的指令来configure your shell (CMD prompt)

C:\Users\NovakZheng>@FOR /f "tokens=*" %i IN ('docker-machine env default') DO @%i

#### 尝试docker指令,检验是否能够执行 , `docker run hello-world`

C:\Users\NovakZheng>docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://cloud.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/


C:\Users\NovakZheng>docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED
STATUS              PORTS               NAMES

以上输出,证明docker环境已经可以在CMD下面运行了。