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 與 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/

相關內容