在远程主机上运行docker run [英] `docker run` on a remote host
问题描述
是否可以(直接使用docker
命令或docker-py
API)从远程主机启动容器?
is it possible (using the docker
command or the docker-py
API directly) to start a container from a remote host?
让我们假设我有两台具有不同体系结构的机器:
-A是x86
机器
-B是ARM
机器
Lets assume I have two machines that have different architectures:
- A is an x86
machine
- B is an ARM
machine
我想使用我的A机器在B机器上运行一个容器.起初,我认为可以使用以下命令:
I would like to run a container on the B machine using my A machine. At first, I thought it was possible using this command:
[A]$> DOCKER_HOST=$MACHINE_B_IP:$MACHIN_B_PORT docker run hello-from-B
但是此命令实际上会拉出图像hello-from-B
并尝试在最终以某些exec format error
结尾的机器A上运行它,这显然导致无法将特定于ARM
的图像运行到x86
机器.
But this command actually pulls the image hello-from-B
and tries to run it on the machine A which ends up on some exec format error
cause obviously you can't run images that are specific to ARM
to an x86
machine.
机器A和B之间的通信运行良好.我可以运行images
或ps
之类的命令,它可以为我带来预期的结果:
Communication between machine A and B is working well. I can run commands like images
or ps
and it gives me the expected results:
[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
并且还没有尝试过,但是据我了解,这不能解决我的问题.
I've heard about docker-machine
and haven't tried it yet, but from my understanding, this won't solve my problem.
有什么方法可以直接使用docker
来实现.一种解决方法可能是使用ssh
连接到远程主机并直接从远程主机使用docker
客户端,但是我想尽可能避免这种解决方案.
Is there any way to achieve that using docker
directly. A workaround might be to using ssh
to connect to the remote host and use the docker
client directly from the remote host, but I'd like to avoid this solution as much as possible.
预先感谢
TL; DR;
DOCKER_HOST=... docker run something
如何在DOCKER_HOST
上运行something
,而不是在我的本地计算机上运行.
How can DOCKER_HOST=... docker run something
runs something
on the DOCKER_HOST
rather than running it on my local machine.
推荐答案
if your targeted machine B could be created on one of these platform then I guess docker-machine would serve your needs. you would create your machine using docker-machine create --driver <..driver setup..> MACHINE_B
then you activate it using eval $(docker-machine env MACHINE_B)
. docker-machine env MACHINE_B
will print out some export statements:
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://...."
export DOCKER_CERT_PATH="/..."
export DOCKER_MACHINE_NAME="MACHINE_B"
一旦您的计算机处于活动状态,就可以像在本地一样使用docker
命令在MACHINE_B上进行远程操作.
once your machine is active, you can use the docker
command as you would locally to act remotely on MACHINE_B.
这篇关于在远程主机上运行docker run的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!