如何使用dockerfile中的mysql配置达到其URL
我有一个WAR文件,其中包含以下MySQL设置;我想使用Dockerfile对其进行编译,以便可以使用MySQL Docker映像。 但是,我缺少/无法正确配置某些内容,因此,我正在收到连接错误。
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"]
构建并运行命令用于图像和容器:
docker build -t="navin/java-app" .
docker run -e "SPRING_PROFILES_ACTIVE=dev" -p 8080:8084 -t navin/java-app
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
纠正我,如果我错了,
MySQL Server的主机是Container1-IP:3307
War App在Container2上,它正在尝试连接到LocalHost:3307
可能会将URL的主机从
local-Host
更改为到192.168.100.19。您可以在第一个容器上使用命令ifconfig
获得实际的IPcorrect 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 container默认Docker容器访问主机IP是
172.17.0.1
,如果您有一个映射到主机的MySQL端口3306,则可以使用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