我已成功设置对运行 openSSH Server(使用公钥身份验证)的 Windows 10 计算机的远程访问。我还在 Windows 计算机上运行 Docker Desktop。
我想从我的 Macbook M1 访问 Windows 机器上的 docker 守护程序和容器(这样我就可以控制在 Windows 机器上的容器中运行的应用程序并为该应用程序开发脚本)。
我的想法基本上来自于本文
我可以通过 ssh 成功连接到 Windows 机器(openSSH 服务器安装在 WSL 2 上,而不是在 linux 发行版内):
Windows 上的 daemon.json:
{
"registry-mirrors": [],
"insecure-registries": [],
"debug": false,
"experimental": false,
"features": {
"buildkit": true
},
"builder": {
"gc": {
"enabled": true,
"defaultKeepStorage": "20GB"
}
},
"hosts": ["tcp://0.0.0.0:2375", "ssh://0.0.0.0:2376"],
"group": "docker"
}
在Macbook上我已经安装了docker 文件并设置DOCKER_HOST:
echo "export DOCKER_HOST=ssh://[email protected]:22" >> ~/.zshrc && source ~/.zshrc
我也尝试使用如下描述的上下文这篇 MS 文章
然后我可以在我的 Macbook 上运行 docker 命令并查看远程 docker 主机和正在运行的容器:
phil@Phil-MacBook:~ > docker version
Client:
Version: 20.10.8
API version: 1.41
Go version: go1.16.6
Git commit: 3967b7d
Built: Fri Jul 30 19:55:20 2021
OS/Arch: darwin/arm64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.8
API version: 1.41 (minimum version 1.12)
Go version: go1.16.6
Git commit: 75249d8
Built: Fri Jul 30 19:52:10 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.9
GitCommit: e25210fe30a0a703442421b0f60afac609f950a3
runc:
Version: 1.0.1
GitCommit: v1.0.1-0-g4144b63
docker-init:
Version: 0.19.0
GitCommit: de40ad0
phil@Phil-MacBook:Docker > docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6449bc460e6b humble_bumble "jupyter notebook --…" 5 days ago Up 5 seconds 0.0.0.0:2375->2375/tcp, :::2375->2375/tcp, 8888/tcp priceless_mahavira
153b9fcb70a9 vsc-docker-0f0a12d517505d0b19ef9dcb95ae109f "jupyter notebook --…" 6 days ago Up 12 hours 8888/tcp gracious_nash
我创建了一个.devcontainer
包含dockerfile
和devcontainer.json
的:
{
"name": "DEV ENV",
"dockerFile": "dockerfile",
"runArgs": ["--init"],
"mounts": [ "source=/var/run/docker.sock,target=/var/run/docker-host.sock,type=bind" ],
"overrideCommand": false,
// Use this environment variable if you need to bind mount your local source code into a new container.
"remoteEnv": {
"LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}"
},
// Set *default* container specific settings.json values on container create.
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-azuretools.vscode-docker",
"kelvin.vscode-sshfs",
"ms-python.python",
"ms-toolsai.jupyter"
],
// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [80,8080,5000,8888,2375]
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "docker --version",
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
//"remoteUser": "vscode"
}
我在 Macbook M1 上的 VS Code(最新版本)中安装了远程容器并列出正在运行的docker:
但是,当我尝试时open folder in container
,它成功地做了一些事情,但随后以下错误中止了该过程:
[2021-10-07T15:11:01.391Z] failed to solve with frontend dockerfile.v0: failed to solve with frontend gateway.v0: rpc error: code = Unknown desc = failed to process "\"dev": unexpected end of statement while looking for matching double-quote
[2021-10-07T15:11:01.394Z] Stop (6252 ms): Run: docker build -f /Users/phil/docker/.devcointainer/dockerfile -t vsc-devcointainer-b8e915c60b425e8ebf3b4086823c8d79 /Users/phil/docker/.devcointainer
[2021-10-07T15:11:01.399Z] Command failed: docker build -f /Users/phil/docker/.devcointainer/dockerfile -t vsc-devcointainer-b8e915c60b425e8ebf3b4086823c8d79 /Users/phil/docker/.devcointainer
当我尝试时Attach to running container
:
[6588 ms] Start: Preparing Extensions
[6589 ms] Start: Run in container: test ! -f '/home/devuser/.vscode-server/data/Machine/.installExtensionsMarker' && set -o noclobber && mkdir -p '/home/devuser/.vscode-server/data/Machine' && { > '/home/devuser/.vscode-server/data/Machine/.installExtensionsMarker' ; } 2> /dev/null
[6593 ms] Error: stream ended with:297 but wanted:1128865906
at u (/Users/phil/.vscode/extensions/ms-vscode-remote.remote-containers-0.194.3/dist/extension/extension.js:7:60200)
at /Users/phil/.vscode/extensions/ms-vscode-remote.remote-containers-0.194.3/dist/extension/extension.js:7:60381
at s (/Users/phil/.vscode/extensions/ms-vscode-remote.remote-containers-0.194.3/dist/extension/extension.js:12:5296)
at Socket.<anonymous> (/Users/phil/.vscode/extensions/ms-vscode-remote.remote-containers-0.194.3/dist/extension/extension.js:12:5466)
at Socket.emit (events.js:327:22)
at endReadableNT (internal/streams/readable.js:1327:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
[6594 ms] Remote-Containers server terminated (code: 126, signal: null).
[6597 ms]
[6597 ms]
[6597 ms] Exit code 1
[6599 ms] Extensions cache, install extensions: None
[6599 ms] Start: Run in container: test -d /home/devuser/.vscode-server/extensionsCache && ls /home/devuser/.vscode-server/extensionsCache || true
[6605 ms] kelvin.vscode-sshfs-1.23.0
ms-azuretools.vscode-docker-1.17.0
ms-python.python-2021.9.1246542782
ms-python.vscode-pylance-2021.9.4
ms-toolsai.jupyter-2021.8.2041215044
ms-toolsai.jupyter-keymap-1.0.0
[6606 ms]
[6606 ms] Extensions cache, copy to remote: None
[6607 ms] Start: Run in container: for pid in `cd /proc && ls -d [0-9]*`; do { echo $pid ; readlink /proc/$pid/cwd ; readlink /proc/$pid/ns/mnt ; cat /proc/$pid/stat | tr "
[6641 ms] Start: Starting VS Code Server
[6642 ms] Start: Run in container: /home/devuser/.vscode-server/bin/7f6ab5485bbc008386c4386d08766667e155244e/server.sh --log debug --force-disable-user-env --port 0 --extensions-download-dir /home/devuser/.vscode-server/extensionsCache --start-server
[6645 ms] Error: stream is closed
at /Users/phil/.vscode/extensions/ms-vscode-remote.remote-containers-0.194.3/dist/extension/extension.js:12:3742
at i (/Users/phil/.vscode/extensions/ms-vscode-remote.remote-containers-0.194.3/dist/extension/extension.js:12:1874)
at EventEmitter.t.<computed> [as exec] (/Users/phil/.vscode/extensions/ms-vscode-remote.remote-containers-0.194.3/dist/extension/extension.js:12:1636)
at u (/Users/phil/.vscode/extensions/ms-vscode-remote.remote-containers-0.194.3/dist/extension/extension.js:128:1024)
at new Promise (<anonymous>)
at /Users/phil/.vscode/extensions/ms-vscode-remote.remote-containers-0.194.3/dist/extension/extension.js:128:1002
at Ln (/Users/phil/.vscode/extensions/ms-vscode-remote.remote-containers-0.194.3/dist/extension/extension.js:171:1779)
at JB (/Users/phil/.vscode/extensions/ms-vscode-remote.remote-containers-0.194.3/dist/extension/extension.js:171:541)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async Ci (/Users/phil/.vscode/extensions/ms-vscode-remote.remote-containers-0.194.3/dist/extension/extension.js:143:7538)
at async pF (/Users/phil/.vscode/extensions/ms-vscode-remote.remote-containers-0.194.3/dist/extension/extension.js:284:1663)
at async /Users/phil/.vscode/extensions/ms-vscode-remote.remote-containers-0.194.3/dist/extension/extension.js:314:1497
[16614 ms] Extensions cache, remote removals: None
我感觉我离成功不远了,因为我可以在 VS Code 中看到容器,但显然我遗漏了一些东西。这可能与不同的架构有关(Macbook M1 是 ARM,而 Windows 是 x86)?