创建网络
docker network create -d overlay \
--scope swarm \
--subnet 172.27.0.0/16 \
--attachable swarm-net
docker-compose 内容
version: '3'
services:
consul:
image: hashicorp/consul:1.18
ports:
- "8500:8500"
volumes:
- ./data:/consul/data
- ./consul.d/:/consul/config:rw
command: >
consul agent -server
-bootstrap-expect=1
-ui
-client=0.0.0.0
-data-dir=/consul/data
--config-dir=/consul/config
-bind '{{ GetPrivateInterfaces | include "network" "172.27.0.0/16" | attr "address" }}'
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8500/ui/dc1/services/consul"]
interval: 30s
timeout: 10s
retries: 3
networks:
- yw-swarm-net
networks:
swarm-net:
external: true
开启acl 配置
cat consul.d/acl.hcl
acl = { enabled = true default_policy = "deny" enable_token_persistence = true }
获得默认token
docker-compose exec consul sh
consul acl bootstrap
SecretID 就是token
AccessorID: 30422e56-e314-9e2c-4f98-4373fa85ae30
SecretID: b25200bf-730c-fe0f-5257-8df238313b25
Description: Bootstrap Token (Global Management)
Local: false
Create Time: 2024-05-23 09:08:04.11698481 +0000 UTC
Policies:
00000000-0000-0000-0000-000000000001 - global-management