git clone https://github.com/nacos-group/nacos-docker.git
cd nacos-docker
create database nacos_config;
use nacos_config;
执行数据库脚本: https://github.com/alibaba/nacos/blob/master/distribution/conf/mysql-schema.sql
vim env/nacos-standlone-mysql.env
# 修改以下配置:
# mysql host
MYSQL_SERVICE_HOST=本机ip
# 数据库名称, 与上面创建的数据库保持一致
MYSQL_SERVICE_DB_NAME=nacos_config
# 端口号
MYSQL_SERVICE_PORT=3306
# 用户名
MYSQL_SERVICE_USER=root
# 密码
MYSQL_SERVICE_PASSWORD=123456
# Using mysql 5.7:
vim example/standalone-mysql-5.7.yaml
# Using mysql 8:
vim example/standalone-mysql-8.yaml
删除:services.depends_on 相关配置
删除:services.mysql 相关配置
修改后:
% cat standalone-mysql-8.yaml
version: "3.8"
services:
nacos:
image: nacos/nacos-server:${NACOS_VERSION}
container_name: nacos-standalone-mysql
env_file:
- ../env/nacos-standlone-mysql.env
volumes:
- ./standalone-logs/:/home/nacos/logs
ports:
- "8848:8848"
- "9848:9848"
restart: always
# Using mysql 5.7:
docker-compose -f example/standalone-mysql-5.7.yaml up
# Using mysql 8:
docker-compose -f example/standalone-mysql-8.yaml up
创建自定义network:
docker network create my-net
将mysql容器加入自定义network:
docker network connect my-net [mysql容器名]
修改配置文件:
vim env/nacos-standlone-mysql.env
修改:MYSQL_SERVICE_HOST 为 [mysql容器名]
修改dockerfile,自定义network:
vim example/standalone-mysql-8.yaml
新增:
networks:
default:
external:
name: my-net
重新执行:
# Using mysql 5.7:
docker-compose -f example/standalone-mysql-5.7.yaml up
# Using mysql 8:
docker-compose -f example/standalone-mysql-8.yaml up
数据库配置有错误