Docker机器群;如何在VM上打开端口 [英] Docker-machine swarm; how to open ports on VM

查看:86
本文介绍了Docker机器群;如何在VM上打开端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

。我已经通过 docker-machine create --driver虚拟框< name> 创建了3个VM。但是我如何在它们上打开端口?

Trying out the new "swarm mode", following this. I have created 3 VM's via docker-machine create --driver virtual box <name>. But how do I open ports on them?

推荐答案

它可能与 docker run -p< public-port>:< internal-port> < image> 在节点上执行。但是,由于您想大量蜂拥而至,我认为最好遵循一个良好的指南来在此处解决路由混乱。如果遵循作者的建议,则需要首先通过 docker-machine 命令创建一个集群(即docker主机集群),例如

It might work with docker run -p <public-port>:<internal-port> <image> executed on the node. However, since you want to run a swarm, I guess it is better to follow a good guide to solve the routing mess here. If you follow the author's suggestions, you need to create a swarm (i.e. the docker host cluster) first by the docker-machine commands, e.g.

docker-machine create --driver virtualbox swarm-1
docker-machine create --driver virtualbox swarm-2

设置群

eval $(docker-machine env swarm-1)
docker swarm init --advertise-addr $(docker-machine ip swarm-1)

与其他机器(如果有)一起加入

join the other machines (if there are any) with

eval $(docker-machine env swarm-2)
docker swarm join \ 
--token <yourtoken> 192.168.99.106:2377

其中< yourtoken> docker swarm init 命令的输出中找到c>。

where <yourtoken>is found in the output of the docker swarm init command.

然后,作者建议创建一个网络

Then the author suggests to create a network with something like

docker network create --driver overlay webnet

并通过定义服务来发布端口,例如

and publish the port by defining a service like

docker service create --name webapp --replicas=2 --network webnet --publish 80:8000 <yourdockerimage>

在此示例中,您的dockerimage在端口8000内部运行服务,该端口映射到docker主机端口80。然后,您可以访问服务,例如

In this example, yourdockerimage is running a service internally on port 8000, which is mapped to the docker host port 80. Then, you can access the service e.g. by

curl http://<IP-address of any Docker swarm node>:80

注意,您可以访问任何Docker swarm节点的IP地址。 Docker swarm将发挥作用,并将请求路由到该服务的容器,即使您已选择没有运行该服务的容器的节点的IP地址。

Note, you can access the IP address of any Docker swarm node. Docker swarm will do the magic and will route the request to a container of this service, even if you have chosen the IP address of a node no container of this service is running on.

这篇关于Docker机器群;如何在VM上打开端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆