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"]
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
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 commandifconfig
on the first containerThe 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