是否可以(直接使用 docker
命令或 docker-py
API)从远程主机启动容器?
假设我有两台具有不同架构的机器:
- A 是 x86
机器
- B 是 ARM
机器
我想使用我的 A 机器在 B 机器上运行一个容器。一开始我以为可以用这个命令:
[A]$> DOCKER_HOST=$MACHINE_B_IP:$MACHIN_B_PORT docker run hello-from-B
但是这个命令实际上拉取了图像 hello-from-B
并尝试在机器 A 上运行它,最终结果为 exec format error
因为很明显你不能运行特定于 ARM
的图像。到 x86
机器。
机器 A 和 B 之间的通信运行良好。我可以运行 images
之类的命令或 ps
它给了我预期的结果:
[A]$> DOCKER_HOST=$MACHINE_B_IP:$MACHIN_B_PORT docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-from-B <none> fd5059044831 13 hours ago 1.26GB
我听说过 docker-machine
还没有尝试过,但据我了解,这并不能解决我的问题。
有什么方法可以使用 docker
直接地。解决方法可能是使用 ssh
连接到远程主机并使用 docker
客户端直接从远程主机,但我想尽可能避免这种解决方案。
提前致谢,
TL;DR;
如何DOCKER_HOST=... docker run something
运行 something
在 DOCKER_HOST
而不是在我的本地机器上运行它。
最佳答案
检查最新的 docker 18.09 是否包含该功能。
见 docker/cli PR 1014
Added support for SSH connection. e.g.
docker -H ssh://me@server
- The cli should accept
ssh://me@server
forDOCKER_HOST
and-H
. Using that would execute ssh with the passed config.- The ssh command would call a hidden command on the docker CLI binary on the remote side. For example, docker dial-stdio.
This command will make a connection to the local
DOCKER_HOST
variable (almost always the default local socket) and forward that connection on the commands stdio.
Even though this command is supposed to run locally to thedockerd
binary, we think that it is an invalid configuration for this feature to remove the localdocker
binary so we can rely on it always being present.How to verify it
docker -H ssh://me@server run -it --rm busybox
目前的 react :
From ops and sysadmins everywhere, we thank you for this fantastic and unexpected feature.
I'm hoping this will seriously cut down the number of times I see people openingdockerd
TCP w/o TLS and just opt for SSH endpoints for remote mgmt.
关于linux - `docker run` 在远程主机上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44446472/