1.拉取容器
docker pull nacos/nacos-server:v2.4.3
2.创建宿主机挂载目录
mkdir -p /docker/nacos/logs/ mkdir -p /docker/nacos/conf/
3.启动临时容器并拷贝配置文件
- 启动临时容器
-
docker run -d --name nacos-temp -p 8848:8848 nacos/nacos-server:v2.4.3
- 拷贝Nacos配置
-
docker cp nacos-temp:/home/nacos/logs/ /data/nacos/ docker cp nacos-temp:/home/nacos/conf/ /data/nacos/
- 移除临时容器
-
docker rm -f nacos-temp
4.查看宿主机的conf的application.properties配置文件是如下:
# spring server.servlet.contextPath=${SERVER_SERVLET_CONTEXTPATH:/nacos} server.contextPath=/nacos server.port=${NACOS_APPLICATION_PORT:8848} server.tomcat.accesslog.max-days=30 server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i %{Request-Source}i server.tomcat.accesslog.enabled=${TOMCAT_ACCESSLOG_ENABLED:false} server.error.include-message=ALWAYS # default current work dir server.tomcat.basedir=file:. #*************** Config Module Related Configurations ***************# ### Deprecated configuration property, it is recommended to use `spring.sql.init.platform` replaced. #spring.datasource.platform=${SPRING_DATASOURCE_PLATFORM:} spring.sql.init.platform=${SPRING_DATASOURCE_PLATFORM:} nacos.cmdb.dumpTaskInterval=3600 nacos.cmdb.eventTaskInterval=10 nacos.cmdb.labelTaskInterval=300 nacos.cmdb.loadDataAtStart=false db.num=${MYSQL_DATABASE_NUM:1} db.url.0=jdbc:mysql://${MYSQL_SERVICE_HOST}:${MYSQL_SERVICE_PORT:3306}/${MYSQL_SERVICE_DB_NAME}?${MYSQL_SERVICE_DB_PARAM:characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false} db.user.0=${MYSQL_SERVICE_USER} db.password.0=${MYSQL_SERVICE_PASSWORD} ## DB connection pool settings db.pool.config.connectionTimeout=${DB_POOL_CONNECTION_TIMEOUT:30000} db.pool.config.validationTimeout=10000 db.pool.config.maximumPoolSize=20 db.pool.config.minimumIdle=2 ### The auth system to use, currently only 'nacos' and 'ldap' is supported: nacos.core.auth.system.type=${NACOS_AUTH_SYSTEM_TYPE:nacos} ### worked when nacos.core.auth.system.type=nacos ### The token expiration in seconds: nacos.core.auth.plugin.nacos.token.expire.seconds=${NACOS_AUTH_TOKEN_EXPIRE_SECONDS:18000} ### The default token: nacos.core.auth.plugin.nacos.token.secret.key=${NACOS_AUTH_TOKEN:} ### Turn on/off caching of auth information. By turning on this switch, the update of auth information would have a 15 seconds delay. nacos.core.auth.caching.enabled=${NACOS_AUTH_CACHE_ENABLE:false} nacos.core.auth.enable.userAgentAuthWhite=${NACOS_AUTH_USER_AGENT_AUTH_WHITE_ENABLE:false} nacos.core.auth.server.identity.key=${NACOS_AUTH_IDENTITY_KEY:} nacos.core.auth.server.identity.value=${NACOS_AUTH_IDENTITY_VALUE:} ## spring security config ### turn off security nacos.security.ignore.urls=${NACOS_SECURITY_IGNORE_URLS:/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**} # metrics for elastic search management.metrics.export.elastic.enabled=false management.metrics.export.influx.enabled=false nacos.naming.distro.taskDispatchThreadCount=10 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.console.ui.enabled=true nacos.core.param.check.enabled=true
5.启动容器的docker-compose.yml也可转换成docker run 命令 如下代码(运行前需要把application.properties):
version: '3' services: nacos: image: nacos/nacos-server:v2.4.3 container_name: nacos environment: - MODE=standalone - SPRING_DATASOURCE_PLATFORM=mysql - MYSQL_SERVICE_HOST=mysql8 - MYSQL_SERVICE_PORT=3306 - MYSQL_SERVICE_DB_NAME=default_nacos - MYSQL_SERVICE_USER=root - MYSQL_SERVICE_PASSWORD=root - MYSQL_SERVICE_DB_PARAM=characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=GMT%2B8 ports: - "8848:8848" - "9848:9848" - "9849:9849" volumes: - ./logs/:/home/nacos/logs - ./conf/:/home/nacos/conf restart: always networks: - cluster1 networks: cluster1: external: true
注:以上Nacos使用的MySQL是另外一个已启动的容器,两容器是在一个宿主机上,且在同一网络下
额外创建网络命令如下:
docker network create [自己定义的网络名称] 创建新网络网络驱动使用docker默认的
docker network ls 查看网络,看是否创建成功
//连接到创建的网络
docker network connect [自己定义的网络名称] [mysql的id]
docker network connect [自己定义的网络名称] [nacos的id]
//查看两容器是否在创建的网络中
docker network inspect [自己定义的网络名称]
标签:SERVICE,MYSQL,Nacos2.4,nacos,auth,server,MySQL,docker,Docker From: https://www.cnblogs.com/xiaoluoye/p/18603384