Вы находитесь на странице: 1из 8

DockerRegistry()

DockerNotary()

OpenSourceatDocker()

About()

Docsarchive()

Advisory: See Swarm mode overview (../../engine/swarm/) for the orchestration features introduced in Docker Engine 1.12. Only
refer to the Docker Swarm documents below for information on the standalone Swarm product.

DockerSwarmDiscovery
Docker Swarm comes with multiple discovery backends. You use a hosted discovery service with Docker Swarm. The service
maintains a list of IPs in your cluster. This page describes the different types of hosted discovery available to you. These are:

Usingadistributedkey/valuestore
The recommended way to do node discovery in Swarm is Dockers libkv project. The libkv project is an abstraction layer over
existing distributed key/value stores. As of this writing, the project supports:
Consul 0.5.1 or higher
Etcd 2.0 or higher
ZooKeeper 3.4.5 or higher
For details about libkv and a detailed technical overview of the supported backends, refer to the libkv project
(https://github.com/docker/libkv).

Usingahosteddiscoverykeystore
1. On each node, start the Swarm agent.
The node IP address doesnt have to be public as long as the Swarm manager can access it. In a large cluster, the nodes
joining swarm may trigger request spikes to discovery. For example, a large number of nodes are added by a script, or
recovered from a network partition. This may result in discovery failure. You can use delay option to specify a delay limit.
Swarm join will add a random delay less than this limit to reduce pressure to discovery.
Etcd:

swarmjoinadvertise=<node_ip:2375>etcd://<etcd_addr1>,<etcd_addr2>/<optionalpathprefix>

Consul:

swarmjoinadvertise=<node_ip:2375>consul://<consul_addr>/<optionalpathprefix>

ZooKeeper:

swarmjoinadvertise=<node_ip:2375>zk://<zookeeper_addr1>,<zookeeper_addr2>/<optionalpathprefix>

2. Start the Swarm manager on any machine or your laptop.


Etcd:

swarmmanageHtcp://<swarm_ip:swarm_port>etcd://<etcd_addr1>,<etcd_addr2>/<optionalpathprefix>

Consul:

swarmmanageHtcp://<swarm_ip:swarm_port>consul://<consul_addr>/<optionalpathprefix>

ZooKeeper:

swarmmanageHtcp://<swarm_ip:swarm_port>zk://<zookeeper_addr1>,<zookeeper_addr2>/<optionalpathprefix>

3. Use the regular Docker commands.

dockerHtcp://<swarm_ip:swarm_port>info
dockerHtcp://<swarm_ip:swarm_port>run...
dockerHtcp://<swarm_ip:swarm_port>ps
dockerHtcp://<swarm_ip:swarm_port>logs...
...

4. Try listing the nodes in your cluster.


Etcd:

swarmlistetcd://<etcd_addr1>,<etcd_addr2>/<optionalpathprefix>
<node_ip:2375>

Consul:

swarmlistconsul://<consul_addr>/<optionalpathprefix>
<node_ip:2375>

ZooKeeper:

swarmlistzk://<zookeeper_addr1>,<zookeeper_addr2>/<optionalpathprefix>
<node_ip:2375>

UseTLSwithdistributedkey/valuediscovery
You can securely talk to the distributed k/v store using TLS. To connect securely to the store, you must generate the certificates
for a node when you join it to the swarm. You can only use with Consul and Etcd. The following example illustrates this with
Consul:

swarmjoin\
advertise=<node_ip:2375>\
discoveryoptkv.cacertfile=/path/to/mycacert.pem\
discoveryoptkv.certfile=/path/to/mycert.pem\
discoveryoptkv.keyfile=/path/to/mykey.pem\
consul://<consul_addr>/<optionalpathprefix>

This works the same way for the Swarm manage and list commands.

Astaticfileorlistofnodes
Note*: This discovery method is incompatible with replicating Swarm managers. If you require replication, you should use
a hosted discovery key store.

You can use a static file or list of nodes for your discovery backend. The file must be stored on a host that is accessible from the
Swarm manager. You can also pass a node list as an option when you start Swarm.
Both the static file and the nodes option support an IP address ranges. To specify a range supply a pattern, for example,
10.0.0.[10:200] refers to nodes starting from 10.0.0.10 to 10.0.0.200 . For example for the file discovery method.

$echo"10.0.0.[11:100]:2375">>/tmp/my_cluster
$echo"10.0.1.[15:20]:2375">>/tmp/my_cluster
$echo"192.168.1.2:[2:20]375">>/tmp/my_cluster

Or with node discovery:

swarmmanageH<swarm_ip:swarm_port>"nodes://10.0.0.[10:200]:2375,10.0.1.[2:250]:2375"

Tocreateafile
1. Edit the file and add line for each of your nodes.

echo<node_ip1:2375>>>/opt/my_cluster
echo<node_ip2:2375>>>/opt/my_cluster
echo<node_ip3:2375>>>/opt/my_cluster

This example creates a file named /tmp/my_cluster . You can use any name you like.
2. Start the Swarm manager on any machine.

swarmmanageHtcp://<swarm_ip:swarm_port>file:///tmp/my_cluster

3. Use the regular Docker commands.

dockerHtcp://<swarm_ip:swarm_port>info
dockerHtcp://<swarm_ip:swarm_port>run...
dockerHtcp://<swarm_ip:swarm_port>ps
dockerHtcp://<swarm_ip:swarm_port>logs...
...

4. List the nodes in your cluster.

$swarmlistfile:///tmp/my_cluster
<node_ip1:2375>
<node_ip2:2375>
<node_ip3:2375>

Touseanodelist
1. Start the manager on any machine or your laptop.

swarmmanageH<swarm_ip:swarm_port>nodes://<node_ip1:2375>,<node_ip2:2375>

or

swarmmanageH<swarm_ip:swarm_port><node_ip1:2375>,<node_ip2:2375>

2. Use the regular Docker commands.

dockerH<swarm_ip:swarm_port>info
dockerH<swarm_ip:swarm_port>run...
dockerH<swarm_ip:swarm_port>ps
dockerH<swarm_ip:swarm_port>logs...

3. List the nodes in your cluster.

$swarmlistfile:///tmp/my_cluster
<node_ip1:2375>
<node_ip2:2375>
<node_ip3:2375>

DockerHubasahosteddiscoveryservice
Warning: The Docker Hub Hosted Discovery Service is not recommended for production use. Its intended to be used for
testing/development. See the discovery backends for production use.

This example uses the hosted discovery service on Docker Hub. Using Docker Hubs hosted discovery service requires that each
node in the swarm is connected to the public internet. To create your cluster:
1. Create a cluster.

$swarmcreate
6856663cdefdec325839a4b7e1de38e8#<thisisyourunique<cluster_id>

2. Create each node and join them to the cluster.


On each of your nodes, start the swarm agent. The node IP address doesnt have to be public (eg. 192.168.0.X) but the the
Swarm manager must be able to access it.

$swarmjoinadvertise=<node_ip:2375>token://<cluster_id>

3. Start the Swarm manager.


This can be on any machine or even your laptop.

$swarmmanageHtcp://<swarm_ip:swarm_port>token://<cluster_id>

4. Use regular Docker commands to interact with your cluster.

dockerHtcp://<swarm_ip:swarm_port>info
dockerHtcp://<swarm_ip:swarm_port>run...
dockerHtcp://<swarm_ip:swarm_port>ps
dockerHtcp://<swarm_ip:swarm_port>logs...
...

5. List the nodes in your cluster.

swarmlisttoken://<cluster_id>
<node_ip:2375>

Contributeanewdiscoverybackend
You can contribute a new discovery backend to Swarm. For information on how to do this, see
github.com/docker/docker/pkg/discovery (https://github.com/docker/docker/tree/master/pkg/discovery).

DockerSwarmdocumentationindex
Docker Swarm overview (../../swarm/)
Scheduler strategies (../../swarm/scheduler/strategy/)
Scheduler filters (../../swarm/scheduler/filter/)
Swarm API (../../swarm/swarm-api/)

Вам также может понравиться