Docker, Springboot and Mysql : com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure

后端 未结 2 985
被撕碎了的回忆
被撕碎了的回忆 2021-01-27 10:51

I try to run a Springboot app with mysql connection on Docker. Without docker, it works well. But when I try to deploy on a container, I have com.mysql.cj.exceptions.CJCom

2条回答
  •  情话喂你
    2021-01-27 11:41

    there is a difference between networks and links. use links like the one below

    version: '2'
    services:
        web:
            build: . 
            links: 
                - "db:database"
        db:
            image: postgres
    

    this switch will add ID and IP address of one docker container in another on. in this way they can connect to each other. for more info check following link.

提交回复
热议问题