如何配置 docker CLI 以从 Git-Bash 上的 minikube 访问 docker 服务器?

How to configure docker CLI to access docker server from minikube on Git-Bash?

我在 windows 10 pro 上的 visual studio 代码上使用 git bash 集成终端。 如果尝试这个命令 eval $(minikube docker-env) 我得到 bash: syntax error near unexpected token('`

然后我尝试 eval '$(minikube docker-env)',我得到了这个错误 bash: You: command not found

如果尝试minikube docker-env我得到

You can further specify your shell with either 'cmd' or 'powershell' with the --shell flag.

SET DOCKER_TLS_VERIFY=1
SET DOCKER_HOST=tcp://192.168.0.164:2376
SET DOCKER_CERT_PATH=C:\Users\migue\.minikube\certs
SET DOCKER_API_VERSION=1.35
REM Run this command to configure your shell:
REM @FOR /f "tokens=*" %i IN ('minikube docker-env') DO @%i

最后,如果我尝试使用 REM @FOR /f "tokens=*" %i IN '('minikube docker-env')' DO @%i,我会得到 bash: REM: command not found

这是 Windows 提供的 cmd.exe Shell 的配置。 如果要使用bash,可以手动配置。根据您的输出,它看起来像:

export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.0.164:2376"
export DOCKER_CERT_PATH="C:\Users\migue\.minikube\certs"

试试这个命令,我认为它会起作用

eval '(minikube docker-env)'

尝试使用

检查 minikube 环境变量
$ printenv 

如果没有,请尝试为 minikube 设置环境变量

将 --shell bash 添加到您的命令中,它将以正确的格式输出命令

eval docker-machine env vmtest2 --shell bash

# Run this command to configure your shell:
# eval $("C:\Users\Simon\bin\docker-machine.exe" env vmtest2 --shell bash)