nacos容器创建+springboot连接配置
拉取nacos镜像
docker pull nacos/nacos-server
查看镜像是否下载成功
docker images
创建nacos挂载目录
mkdir -p /home/zhangdan/nacos/logs/
mkdir -p /home/zhangdan/nacos/init.d/
vi /home/zhangdan/nacos/init.d/custom.properties
custom.properties
server.contextPath=/nacos
server.servlet.contextPath=/nacos
server.port=8848
spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://127.0.0.1:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=root
db.password=xxxx
nacos.cmdb.dumpTaskInterval=3600
nacos.cmdb.eventTaskInterval=10
nacos.cmdb.labelTaskInterval=300
nacos.cmdb.loadDataAtStart=false
management.metrics.export.elastic.enabled=false
management.metrics.export.influx.enabled=false
server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i
nacos.security.ignore.urls=/,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/login,/v1/console/health/**,/v1/cs/**,/v1/ns/**,/v1/cmdb/**,/actuator/**,/v1/console/server/**
nacos.naming.distro.taskDispatchThreadCount=1
nacos.naming.distro.taskDispatchPeriod=200
nacos.naming.distro.batchSyncKeyCount=1000
nacos.naming.distro.initDataRatio=0.9
nacos.naming.distro.syncRetryDelay=5000
nacos.naming.data.warmup=true
nacos.naming.expireInstance=true
创建Nacos容器
docker run \
--name nacos -d \
--net mynet \
-p 8848:8848 \
--privileged=true \
--restart=always \
--restart=always \
-e JVM_XMS=256m \
-e JVM_XMX=256m \
-e MODE=standalone \
-e PREFER_HOST_MODE=hostname \
-v /home/zhangdan/nacos/logs:/home/nacos/logs \
-v /home/zhangdan/nacos/init.d/custom.properties:/home/nacos/init.d/custom.properties \
nacos/nacos-server
访问nacos
http://ip:8848/nacos/
用户名/密码 nacos/nacos
springboot nacos 连接配置
spring.profiles.active=local
spring.application.name=system
spring.cloud.nacos.config.file-extension=yaml
spring.cloud.nacos.config.server-addr=nacosdb:8848
spring.cloud.nacos.config.group=DEFAULT_GROUP
spring.cloud.nacos.discovery.server-addr=nacosdb:8848
#主要
spring.cloud.inetutils.ignored-interfaces=eth.*
#docker每个容器都有自己的ip,使用正则表达式匹配应用ip.192.168.0 是自定义网络定义的ip
spring.cloud.inetutils.preferred-networks=192.168.0
注:
需先自定义网络,这样nacos feign调用才能找到应用