I'm trying to create docker containers on mi local enviroment. We have a Micronaut (Java) application and a MySQL database.
I created a container for my database with:
docker run -p 3307:3306 --name mysql-example -e MYSQL_ROOT_PASSWORD=password -d mysql
When I connect from my app in and embbebed server outside of docker we can connect without problems. Mi application.yml have the next configuration:
datasources:
default:
url: jdbc:mysql://localhost:3307/example?allowPublicKeyRetrieval=true&generateSimpleParameterMetadata=true&zeroDateTimeBehavior=convertToNull&verifyServerCertificate=false&useSSL=false
driverClassName: com.mysql.cj.jdbc.Driver
username: root
password: password
schema-generate: CREATE_DROP
dialect: MYSQL
Then I tried to create the Micronaut app image and run it on a container. My Dockerfile contains:
FROM maven:3.6.1-jdk-8
COPY target/example-0.1.jar example.jar
EXPOSE 8080
CMD java -Dcom.sun.management.jmxremote -Xmx128m -jar example.jar
I first generate JAR:
mvnw package
And then I generate docker image:
docker build -t example .
And when I test my app deployed in a container I have the next exception:
Caused by: java.net.ConnectException: Connection refused (Connection refused)
Could you help me with this issue? Thanks :-)