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.cnfor/etc/my.cnf.d/server.cnf) - Find the
bind-addressline and change it to your host’s internal IP address (e.g.,192.168.1.100) or0.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-passwordwith your actual password forbeberu):
TheGRANT ALL PRIVILEGES ON datasource.* TO 'beberu'@'%' IDENTIFIED BY 'your-password'; FLUSH PRIVILEGES;%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.xmlfile in your Knowage container (or edit the host-mounted file directly if you set up volume mounting) - For the
jdbc/datasourceresource, replaceip-addrwith your host’s internal IP address (do not use127.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/knowageresource (assuming your Knowage core database is namedknowage):<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
ResourceLinkentry 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:
If you see a connection response, you’re set. If not, double-check your firewall rules and MariaDB bind settings.docker exec -it your-knowage-container-name telnet 192.168.1.100 3306 - 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.internalinstead 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.logfor details on failed connection attempts.
内容的提问来源于stack exchange,提问作者polycarp royal




