• docker 运行 springboot采坑


    1.当在虚拟机上运行docker命令启动mysql后,命令行登录mysql ,总是报如下错:

    got an error reading communication packets

    后来发现mysql容器(docker logs 容器名)总是启动就报错,然后闪退,后来查了资料,想到是selinux没关,导致的

    2.当mysql正常启动后,尝试在虚拟机上运行 命令行登录 mysql

    error: ‘Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)’
    好像刚启动的mysql 需要设置root用户 ,才能从外部 用mysql 命令行登录

    首先docker exec -it 容器名 /bin/bash 然后从容器中 登录 mysql

    mysql -uroot -p
    UPDATE mysql.user SET host='%' WHERE user='root';
    grant all privileges on *.*  to 'root'@'%';
    flush privileges;
    
    • 1
    • 2
    • 3
    • 4

    然后我又重启了容器
    然后在虚拟机中 mysql -uroot -p -h 127.0.0.1 ,成功
    我的情况是这个 -h 参数很奇妙 ,好像加了才行。

    3.当在虚拟机 启动jar包,启动日志中报 Communications link failure

    Establishing SSL connection without server’s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn’t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to ‘false’. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
    不建议在没有服务器身份验证的情况下建立SSL连接。根据MySQL 5.5.45+、5.6.26+和5.7.6+的要求,如果不设置显式选项,则必须建立默认的SSL连接。需要通过设置useSSL=false来显式禁用SSL,或者设置useSSL=true并为服务器证书验证提供信任存储。
    我的mysql 是 5.7 springboot 2.1.0版本 加上该参数
    类似
    jdbc:mysql://192.168.221.201:3306/jdbc?useSSL=false
    成功

    4.spring boot 启动成功,但是从宿主机浏览器 访问 ip:port 不能访问!
    防火墙? 嗯 关掉
    service iptables stop

    命令行开启 相关端口

    使用如下命令可以临时开启80端口:
    /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT

    终于搞定
    参考宿主机无法访问虚拟机中的web服务
    Docker 拉取 MySQL,SpringBoot2.x 连接提示 Communications link failure

  • 相关阅读:
    ccpc宠物对战
    20-SpringCloudAlibaba-2
    Vue2 04 Axios 异步通讯
    HTML流星雨
    admin后台管理
    Vue_路由VueRoute
    使用Springboot时,Controller层有方法的参数是一个实体类,但是并不需要其中所有的参数
    手机的网费
    卷积网络的发展历史-LeNet
    SpringBoot+Vue项目校园在线拍卖系统
  • 原文地址:https://blog.csdn.net/whp404/article/details/125631029