My goal is to deploy a Rest API on a docker container but I have the following error
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
Firstly, I created the mysql container with the following line of code:
docker run -d -p 3307:3306 --name mysqldb -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=user mysql
it succesfully connected, but when I want to create the api container I got the error, this is the line of code that I typed:
docker run -p 9090:8080 --name myuserapp --net spring-net -e MYSQL_HOST=mysqldb -e MYSQL_USER=root -e MYSQL_PASSWORD=root -e MYSQL_PORT=3306 userapp/service
Additionally, I add my configuraton properties and Dockerfile files:
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://localhost:3307/user
spring.datasource.username=root
spring.datasource.password=root
Dockerfile:
FROM openjdk:11 as build
MAINTAINER Andres
COPY target/user-0.0.1-SNAPSHOT.jar user-0.0.1-SNAPSHOT.jar
ENTRYPOINT ["java", "-jar","user-0.0.1-SNAPSHOT.jar"]
I really appreciate if someone can help me.
spring-net). Also, you are usinglocalhostin your configuration file(?), it should bemysqldb.