wso2 apim /身份服务器docker中的mysql连接错误

问题描述 投票:0回答:2

我有3个dockerfiles用于WSO2 apim,身份服务器和mysql。使用docker-compose来运行这些。相应的docker-compose.yml如下: -

    # docker-compose version
version: "3.7"

# services/containers to be run
services:
  wso2am:
    build: ./apim
    image: wso2am:2.6.0
    ports:
      - "9443:9443"
    links:
      - mysql-db
      - wso2is-km
  wso2is-km:
    build: ./is-as-km
    image: wso2is-km:5.7.0
    ports:
      - "9444:9444"
    links:
      - mysql-db
  mysql-db:
    build: ./mysql
    image: mysql:5.7.26
    ports:
      - "3306:3306"
      - "33060:33060"

在没有将h2数据库更改为mysql的情况下运行时,Identity Server / apim分别在端口9444/9443处正常工作。另外在mysql docker中,从apim / identity服务器的datascripts文件夹创建了regdb / apidb sql数据库。

# Derived from official mysql image (our base image)
FROM mysql:5.7
MAINTAINER Abhilash K R <[email protected]>

ENV MYSQL_ROOT_PASSWORD root
# Add a user
ENV MYSQL_USER wso2carbon
ENV MYSQL_PASSWORD wso2carbon

# Add the content of the sql-scripts/ directory to your image
# All scripts in docker-entrypoint-initdb.d/ are automatically
COPY sql-scripts/ /docker-entrypoint-initdb.d
# expose ports
EXPOSE 3306 33060

添加了jdbc驱动程序并添加了新的db url,如下所示:

<datasource>
            <name>WSO2_CARBON_DB</name>
            <description>The datasource used for registry and user manager</description>
            <jndiConfig>
                <name>jdbc/WSO2CarbonDB</name>
            </jndiConfig>
            <definition type="RDBMS">
                <configuration>
                    <url>jdbc:mysql://localhost:3306/regdb</url>
                    <username>wso2carbon</username>
                    <password>wso2carbon</password>
                    <driverClassName>com.mysql.cj.jdbc.Driver</driverClassName>
                    <maxActive>50</maxActive>
                    <maxWait>60000</maxWait>
                    <testOnBorrow>true</testOnBorrow>
                    <validationQuery>SELECT 1</validationQuery>
                    <validationInterval>30000</validationInterval>
                    <defaultAutoCommit>true</defaultAutoCommit>
                </configuration>
            </definition>
        </datasource>

得到如下错误:enter image description here enter image description here认为错误是在url jdbc:mysql:// localhost:3306 / regdb,试图给dockerhost的localhost / ip也仍然没有工作。

mysql docker wso2 wso2is wso2-am
2个回答
0
投票

尝试更改mysql连接字符串,如下所示 -

<url>jdbc:mysql:jdbc:mysql://mysql-db:3306/regdb</url>

在撰写时,服务可以通过其名称本身来访问。无需使用links等。如果您有相互依赖的服务,您可以使用depends_onservice_healthy

Ref - https://docs.docker.com/compose/compose-file/compose-file-v2/#depends_on


0
投票

这是由于连接到用户数据库时出错。您能否验证为此数据库配置的用户名和密码是否正确?

© www.soinside.com 2019 - 2024. All rights reserved.