【问题标题】:Jhipster connexion to Mysql database in dockerJhipster 连接到 docker 中的 Mysql 数据库
【发布时间】:2020-12-21 17:01:38
【问题描述】:

如何在我的 jhipster 应用程序的 application.yml 中连接我的 mysql 数据库?

这是我的码头工人信息:

【问题讨论】:

    标签: spring-boot docker jhipster


    【解决方案1】:

    通过在 docker run 命令中添加 - - net=host 将 docker 端口公开给主机网络。然后您的应用程序可以像 localhost:YourPort 一样访问它

    例如

       Docker run mysql --net=host
    

    【讨论】:

      【解决方案2】:

      我找到了办法。

      • 下载 postgres 镜像:docker pull postgres:alpine

      • 创建一个 docker 数据库并确定从 docker 连接到哪个端口: docker run --name myUserName -e POSTGRES_PASSWORD=myPassword -d -p 5432:5432 postgres:alpine

      • 进入 docker 容器:docker exec -it containerID bash

      • 连接到 postresql:psql -U postgres myUserName

      • 创建数据库:create database databaseName;

      • 现在在 docker 之外,在您的 application.yml 中:
        数据源: 类型:com.zaxxer.hikari.HikariDataSource 网址:jdbc:postgresql://localhost:5432/bnksearch?useUnicode=true&characterEncoding=utf8&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC&createDatabaseIfNotExist=true

        用户名:postgres

        密码:postgres

        光:

        poolName: Hikari
        
        auto-commit: false
        
        data-source-properties:
        
          cachePrepStmts: true
        
          prepStmtCacheSize: 250
        
          prepStmtCacheSqlLimit: 2048
        
          useServerPrepStmts: true
        

      【讨论】:

        猜你喜欢
        • 2018-11-30
        • 1970-01-01
        • 2017-11-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-03-12
        • 2022-01-07
        • 1970-01-01
        相关资源
        最近更新 更多