You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Docker部署Knowage连接宿主机MariaDB配置问题咨询

Fixing Knowage Docker Container Connection to Host's MariaDB (CentOS 7)

Let’s walk through getting your Knowage container connected to the MariaDB instance running on your CentOS 7 host. I’ll use the config snippets you shared as a starting point and cover all critical steps to resolve this.

Step 1: Update MariaDB’s Network Listening Settings

By default, MariaDB on CentOS 7 only listens on 127.0.0.1—this means your Docker container can’t reach it. Here’s how to adjust that:

  • Open your MariaDB config file (usually at /etc/my.cnf or /etc/my.cnf.d/server.cnf)
  • Find the bind-address line and change it to your host’s internal IP address (e.g., 192.168.1.100) or 0.0.0.0 (to listen on all network interfaces):
    bind-address = 192.168.1.100
    
  • Restart MariaDB to apply changes:
    sudo systemctl restart mariadb
    
  • Open port 3306 in your CentOS firewall to allow container traffic:
    sudo firewall-cmd --add-port=3306/tcp --permanent
    sudo firewall-cmd --reload
    

Step 2: Grant MariaDB User Access from the Container

Your beberu user likely only has permissions to connect from localhost. Let’s update that to allow connections from the Docker network:

  • Log into your MariaDB shell:
    mysql -u root -p
    
  • Run these SQL commands (replace your-password with your actual password for beberu):
    GRANT ALL PRIVILEGES ON datasource.* TO 'beberu'@'%' IDENTIFIED BY 'your-password';
    FLUSH PRIVILEGES;
    
    The % allows connections from any IP (great for testing; you can restrict it to your Docker subnet later for better security).

Step 3: Correct the Knowage server.xml Configuration

Looking at your config snippets, the main issue is the database URL pointing to an incorrect IP. Here’s how to fix it:

  • Locate the server.xml file in your Knowage container (or edit the host-mounted file directly if you set up volume mounting)
  • For the jdbc/datasource resource, replace ip-addr with your host’s internal IP address (do not use 127.0.0.1—that points to the container itself, not the host):
    <Resource name="jdbc/datasource" auth="Container" type="javax.sql.DataSource"
              driverClassName="org.mariadb.jdbc.Driver"
              url="jdbc:mariadb://192.168.1.100:3306/datasource"
              username="beberu" password="your-password"
              maxActive="20" maxIdle="10" maxWait="-1"/>
    
  • Fix the incomplete jdbc/knowage resource (assuming your Knowage core database is named knowage):
    <Resource auth="Container" driverClassName="org.mariadb.jdbc.Driver"
              maxActive="20" maxIdle="10" maxWait="-1"
              name="jdbc/knowage" type="javax.sql.DataSource"
              url="jdbc:mariadb://192.168.1.100:3306/knowage"
              username="your-knowage-db-user" password="your-knowage-db-password"/>
    
  • Keep the ResourceLink entry as-is—it maps the global datasource to the web app context:
    <ResourceLink global="jdbc/datasource" name="jdbc/datasource" type="javax.sql.DataSource"/>
    

Step 4: Test Connectivity & Restart the Container

  • Verify the container can reach your host’s MariaDB:
    docker exec -it your-knowage-container-name telnet 192.168.1.100 3306
    
    If you see a connection response, you’re set. If not, double-check your firewall rules and MariaDB bind settings.
  • Restart the Knowage container to apply the config changes:
    docker restart your-knowage-container-name
    

Quick Troubleshooting Tips

  • Skip localhost/127.0.0.1: These resolve to the container’s own loopback interface, not the host. Always use the host’s internal IP.
  • Docker Host Alias: If your Docker version supports it, you can use host.docker.internal instead of the IP (works on most modern Docker setups, but CentOS 7 may require a newer Docker version).
  • Check MariaDB Logs: If you get access denied errors, check /var/log/mariadb/mariadb.log for details on failed connection attempts.

内容的提问来源于stack exchange,提问作者polycarp royal

火山引擎 最新活动