按照官方推荐方式安装nacos单机版连接自己docker已存在的数据库,发现nacos服务起来了,但无法访问。
下载nacos项目
git clone https://github.com/nacos-group/nacos-docker.git
cd nacos-docker
修改standalone-mysql-8.yaml如下
version: "2"
services:
nacos:
image: nacos/nacos-server:1.3.1
container_name: nacos-standalone-mysql
env_file:
- ../env/nacos-standlone-mysql.env
volumes:
- ./standalone-logs/:/home/nacos/logs
- ./init.d/custom.properties:/home/nacos/init.d/custom.properties
ports:
- "8848:8848"
- "9555:9555"
depends_on:
- test-mysql #修改为外部的mysql 记得需要处于同一个网络
restart: always
修改nacos-standlone-mysql.env配置文件
PREFER_HOST_MODE=hostname
MODE=standalone
SPRING_DATASOURCE_PLATFORM=mysql
MYSQL_SERVICE_HOST=test-mysql
MYSQL_SERVICE_DB_NAME=nacos_config
MYSQL_SERVICE_PORT=3306
MYSQL_SERVICE_USER=root
MYSQL_SERVICE_PASSWORD=xxx
MYSQL_DATABASE_NUM=2 #注意需要配置 默认是1 看官网显示默认是2
docker-compose单机安装
docker-compose -f example/standalone-mysql-8.yaml up -d
ip:8848/nacos访问即可