最近在docker部署了一個Javaweb項目運行的環境,在容器中部署了mysql和Javaweb項目,但是本地可以跑項目,放到容器里面不行。
具體報錯內容是不能訪問數據庫。
Could not get JDBC Connection; nested exception is com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
最后終於找到問題了,是docker里面的防火牆開啟了,
解決方案是關閉防火牆。
1、查看防火牆狀態
firewall-cmd --state
如果命令報錯,賦予特權
docker run -tdi --privileged centos init
2、停止防火牆
systemctl stop firewalld.service
3、禁止firewall開機啟動
systemctl disable firewalld.service
最后終於可以跑起來了