Now that we have a base configuration of setting up a Docker host, let us move to the next level and set up a Docker Swarm cluster automatically:
- First, we need a way to store the Docker Swarm join token securely. We will use chef-vault as a way to store the token. To be able to use chef-vault, we will simply add it as a dependency of our cookbook in cookbooks/dockerhost/metadata.rb:
name 'dockerhost'
# ...
version '0.1.0'
depends 'docker', '~> 4.7'
depends 'chef-vault', '~> 3.1' # update here
- Next, we will create a Chef recipe for initializing the manager node in cookbooks/dockerhost/recipes/manager.rb:
include_recipe 'dockerhost::base'
execute 'init swarm' do
command 'docker swarm init'
not_if 'docker info -f "{{.Swarm.LocalNodeState}}" |...