1、编写docker-compose.yml文件
version: "3.1"
services:
nacos:
restart: always
image: nacos/nacos-server:v2.2.3
container_name: nacos
environment:
- NACOS_AUTH_ENABLE=true
- MODE=standalone
- NACOS_AUTH_TOKEN=8b92c609089f74db3c5ee04bd7d4d89e8b92c609089f74db3c5ee04bd7d4d89e
- NACOS_AUTH_IDENTITY_KEY=nacos
- NACOS_AUTH_IDENTITY_VALUE=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjpbeyJ4eHh4IjoieXl5In1dLCJpYXQiOjE2Nzk1NzU0NzIsImV4cCI6MTY3OTUwMDc5OSwiYXVkIjoiIiwiaXNzIjoiIiwic3ViIjoiIn0.nhN_hKcnjlX0QW-kQj2beLehBzrQnB1IhhJZe2WO-c0
volumes:
- ./data:/home/nacos/data
ports:
- "8848:8848"
- "9848:9848"
2、登录nacos,创建账号配置账号密码及权限
创建账号
绑定角色
权限管理
3、java应用程序配置账号密码
boostrap.yml配置文件内容
配置如下
spring:
application:
name: wallet-service
cloud:
nacos:
config:
server-addr: nacos:8848
file-extension: yml
username: wallet
password: wallet
discovery:
server-addr: nacos:8848
username: wallet
password: wallet
main:
allow-bean-definition-overriding: true
profiles:
active: dev