• docker 安装nacos,使用自定义mysql


    Clone 项目

    git clone https://github.com/nacos-group/nacos-docker.git
    cd nacos-docker
    
    • 1
    • 2

    使用自定义数据库

    • 创建数据库
        create database nacos_config;
        use nacos_config;
    
    • 1
    • 2
    • 初始化表结构
    执行数据库脚本: https://github.com/alibaba/nacos/blob/master/distribution/conf/mysql-schema.sql
    
    • 1
    • 修改配置文件
    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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    # 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
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 执行
    # 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
    
    • 1
    • 2
    • 3
    • 4

    mysql配置为容器名:

    创建自定义network

    docker network create my-net
    
    • 1

    将mysql容器加入自定义network:

    docker network connect my-net [mysql容器名]
    
    • 1

    修改配置文件

    vim env/nacos-standlone-mysql.env
    修改:MYSQL_SERVICE_HOST 为 [mysql容器名]
    
    • 1
    • 2

    修改dockerfile,自定义network:

    vim example/standalone-mysql-8.yaml
    新增:
    networks:
      default:
        external:
          name: my-net
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    重新执行:

    # 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
    
    • 1
    • 2
    • 3
    • 4

    异常:

    • No DataSource set
    数据库配置有错误
    
    • 1
  • 相关阅读:
    Dunham‘s sports EDI需求分析
    高并发下的服务容错
    leetcode热题HOT 238. 除自身以外数组的乘积
    到底什么是“算力网络”?
    Postman和Jmeter的区别
    web学生网页设计作业源码 HTML+CSS+JS 网上鲜花商城购物网站
    vue.js javascript页面表单验证滚动
    难辨真假的Midjourney案例(附提示词):适合练手
    【反射】Constructor类
    玩转ChatGPT:快速制作PPT
  • 原文地址:https://blog.csdn.net/qq_37751454/article/details/133133304