dockerswarminit

January 31, 2025 ยท View on GitHub

The docker_swarm_init resource initializes a new Docker swarm cluster.

Actions

  • :init - Initialize a new swarm
  • :leave - Leave the swarm (must be run on a manager node)

Properties

PropertyTypeDefaultDescription
advertise_addrStringnilAdvertised address for other nodes to connect
autolock[true, false]falseEnable manager auto-locking
cert_expiryStringnilValidity period for node certificates
data_path_addrStringnilAddress for data path traffic
dispatcher_heartbeatStringnilDispatcher heartbeat period
force_new_cluster[true, false]falseForce create a new cluster from current state
listen_addrStringnilListen address
max_snapshotsIntegernilNumber of snapshots to keep
snapshot_intervalIntegernilNumber of log entries between snapshots
task_history_limitIntegernilTask history retention limit

Examples

Initialize a basic swarm

docker_swarm_init 'default' do
  advertise_addr '192.168.1.2'
  listen_addr '0.0.0.0:2377'
end

Initialize a swarm with auto-locking enabled

docker_swarm_init 'secure' do
  advertise_addr '192.168.1.2'
  autolock true
  cert_expiry '48h'
end

Leave a swarm

docker_swarm_init 'default' do
  action :leave
end

Notes

  • Only initialize a swarm on one node - other nodes should join using docker_swarm_join
  • The node that initializes the swarm becomes the first manager
  • Auto-locking requires additional security steps to unlock managers after a restart
  • The worker token is automatically stored in node attributes for use by worker nodes