Windows/cygwin环境下运行Docker

Windows/cygwin环境下运行Docker

我不确定这是否是询问我的问题的正确社区,因为我实际上正在尝试docker在.安装 Docker Toolbox 后,我尝试在 cygwin shell 中启动并获取:cygwinwindowsdocker version

$ docker version
Could not read CA certificate "\\cygdrive\\c\\Users\\Alexey\\.docker\\machine\\machines\\default\\ca.pem": open \cygdrive\c\Users\Alexey\.docker\machine\machines\default\ca.pem: The system cannot find the path specified.

但是,实际文件 /cygdrive/c/Users/Alexey/.docker/machine/machines/default/ca.pem 就在那里,问题似乎出在证书文件路径中的错误斜杠(Windows vs UNIX)。但我不知道在哪里可以修复它。

以下是 ~/.bash_profile 中设置的环境变量:

export DOCKER_HOST=tcp://192.168.99.100:2376
export DOCKER_MACHINE_NAME=default
export DOCKER_TLS_VERIFY=1
export DOCKER_CERT_PATH=/cygdrive/c/Users/Alexey/.docker/machine/machines/default
export TERM=cygwin

更新

Alexey@Alexey-PC ~
$ echo $DOCKER_CERT_PATH
/cygdrive/c/Users/Alexey/.docker/machine/machines/default/

Alexey@Alexey-PC ~
$ docker version
Could not read CA certificate "\\cygdrive\\c\\Users\\Alexey\\.docker\\machine\\machines\\default\\ca.pem": open \cygdrive\c\Users\Alexey\.docker\machine\machines\default\ca.pem: The system cannot find the path specified.

解决方案正如@cloverhap下面建议的,我们需要设置DOCKER_CERT_PATH环境变量,但它应该包含windows路径,而不是cygwin,而且反斜杠应该被转义,所以解决方案是添加以下内容:

export DOCKER_CERT_PATH=C:\\Users\\%USERNAME%\\.docker\\machine\\machines\\default

.bash_profile

答案1

在我的 cygwin 环境中,docker 证书路径实际上设置如下,并且 docker 似乎工作正常。

DOCKER_CERT_PATH=C:\Users\user\.docker\machine\machines\default

下面确实报错

DOCKER_CERT_PATH=/cygdrive/c/Users/user/.docker/machine/machines/default
$ docker version
Could not read CA certificate "\\cygdrive\\c\\Users\\user\\.docker\\machine\\machines\\default\\ca.pem": open \cygdrive\c\Users\user\.docker\machine\machines\default\ca.pem: The system cannot find the path specified.

因此,请尝试将 DOCKER_CERT_PATH 更改为常规 Windows 路径格式。

export DOCKER_CERT_PATH=C:\\Users\\Alexey\\.docker\\machine\\machines\\default

我的docker版本是1.10.1,如果结果有什么不同的话。

答案2

我遇到了同样的问题,然后我意识到当我在 Windows 10 系统上安装 docker 时,有一个名为“Docker快速入门终端”已安装。如果你运行它,会给出一个 bash shell,你可以在该终端中运行你的 docker 命令。这可能不是 Cygwin 的 bash,但那又怎样呢?

在此输入图像描述

这启动了这个……

在此输入图像描述

答案3

这里指出的解决方案都不适合我。我发现即使使用 Cywin,您也必须在 Docker Desktop 的 GUI 中配置代理: 在此输入图像描述

之后我就可以运行:

$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pulling fs layer
1b930d010525: Verifying Checksum
1b930d010525: Download complete
1b930d010525: Pull complete
Digest: sha256:2557e3c07ed1e38f26e389462d03ed943586f744621577a99efb77324b0fe535
Status: Downloaded newer image for hello-world:latest

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.
    (amd64)
 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://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

相关内容