我想从 wsl 开始从事 openshift 项目。我已经在 Windows 上设置了 Minishift 和 VirtualBox,并且据我所知,我已经像这样正确地为所有内容设置了别名。
alias minishift='/mnt/c/Users/<username>/minishift-#####/minishift.exe'
#Sets oc binary alias
alias oc="$(wslpath -a $(minishift oc-env | grep -oP "(?<=PATH=)[^;]+"))/oc.exe"
#Sets docker environment variables
for i in $(minishift docker-env | awk '/SET/{print $2}');do if $( echo ${i} | grep -q 'DOCKER_CERT_PATH' );then eval DOCKER_CERT_PATH=$(wslpath -a $(echo ${i} | grep -oP "C:.*$"));else eval ${i};fi;done
但是,我无法从 wsl 访问本地 docker 注册表。
$ oc whoami -t | docker login -u developer --password-stdin $(minishift openshift registry)
INFO[0015] Error logging in to v2 endpoint, trying next endpoint: Get https://172.30.1.1:5000/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
INFO[0036] Error logging in to v1 endpoint, trying next endpoint: Get https://172.30.1.1:5000/v1/users/: dial tcp 172.30.1.1:5000: connect: connection refused
Get https://172.30.1.1:5000/v1/users/: dial tcp 172.30.1.1:5000: connect: connection refused
我不是 Docker 专家,但令我困惑的是,这个 IP 与 DOCKER_HOST 不同。它在 Windows 上运行良好。
C:\Users\${username}>oc whoami -t | docker login -u developer --password-stdin 172.30.1.1:5000
Login Succeeded
也许 docker 注册表是在 virtualbox 上的仅主机适配器上设置的,因此 wsl 可能无法与其通信?
非常欢迎对我预期的设置提出任何见解或建议。
答案1
我意识到我实际上并没有导出我在 WSL 中设置的变量。真糟糕。
将我的一行代码更改为以下内容,即可使用 wsl docker 客户端登录
for i in $(minishift docker-env | awk '/SET/{print $2}');do if $( echo ${i} | grep -q 'DOCKER_CERT_PATH' );then eval export DOCKER_CERT_PATH=$(wslpath -a $(echo ${i} | grep -oP "C:.*$"));else eval export ${i};fi;done
$ oc whoami -t | docker login -u developer --password-stdin $(minishift openshift registry)
Login Succeeded