我正在尝试将Spring-Boot应用程序(一个容器)连接到MySQL数据库(另一个容器)。启动Java应用程序时出现以下错误:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:通信链接失败
这是我的docker-compose.yml:
version: "3"
services:
db:
image: mysql:8
environment:
- MYSQL_ROOT_PASSWORD=family
- MYSQL_DATABASE=family_db
- MYSQL_USER=family_user
- MYSQL_PASSWORD=family
ports:
- 9999:3306
web:
build:
context: .
dockerfile: Dockerfile-spring
image: family:latest
depends_on:
- db
ports:
- 0:8080
environment:
# - DATABASE_HOST=db
- DATABASE_USER=family_user
- DATABASE_PASSWORD=family
- DATABASE_NAME=family_db
- DATABASE_PORT=3306
# - SPRING_DATASOURCE_URL=jdbc:mysql://mysql:3306/family_db?useUnicode=true&characterEncoding=utf8&useSSL=false
# - spring.datasource.url=jdbc:mysql://mysql:3306/test?useSSL=false
# - spring.datasource.username=family_user
# - spring.datasource.password=family
# - spring.datasource.driver-class-name=com.mysql.jdbc.Driver
angular:
container_name: angular-container
build:
context: angular-app
dockerfile: Dockerfile-angular
ports:
- 0:80
这是我的Dockerfile-spring:
FROM openjdk:8
VOLUME /tmp<br> COPY target/family.jar app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","app.jar"]
我应该怎么做才能为我的Spring-Boot应用程序打开MySQL端口?
答案 0 :(得分:0)
解决方案是使用网桥驱动程序为Docker创建自己的网络。