skip to Main Content

I have one war file with the following MySQL setup; I wanted to compile it using Dockerfile so that I could utilise the mysql docker image.
However, I am missing/not properly configuring something, and as a result, I am receiving connection errors.

        url: jdbc:mysql://localhost:3307/test-db
        username: root
        password: yum-hai-hum

DockerFile

FROM mysql:5.7
ADD test-db.sql /docker-entrypoint-initdb.d
EXPOSE 3307

ENV MYSQL_ROOT_PASSWORD=yum-hai-hum
ENV MYSQL_DATABASE=test-db
ENV MYSQL_USER=root
ENV MYSQL_PASSWORD=yum-hai-hum

FROM openjdk:8-jdk-alpine
ARG JAR_FILE=build/libs/*.war
COPY ${JAR_FILE} app.war

ENTRYPOINT ["java","-jar","/app.war"]

Error:
enter image description here

Build and run command for image and container:

docker build -t="navin/java-app" .
docker run -e "SPRING_PROFILES_ACTIVE=dev" -p 8080:8084 -t navin/java-app

2

Answers


  1. url: jdbc:mysql://localhost:3307/test-db
    

    correct me if i`m wrong,

    The host of Mysql server is container1-ip:3307

    the war app is on container2, and it is trying to connect to localhost:3307

    probably change host of url from localhost to something like 192.168.100.19. You can get the actual ip using command ifconfig on the first container

    Login or Signup to reply.
  2. The default Docker container access host IP is 172.17.0.1 , If you have a MySQL port 3306 that maps to the host, you can use the

    url: jdbc:mysql://172.17.0.1:3306/test-db
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search