gpt4 book ai didi

java - 使用 docker-compose 启动 dockerized Spring Boot 和 MariaDb 时出现连接拒绝错误

转载 作者:行者123 更新时间:2023-11-29 04:16:38 26 4
gpt4 key购买 nike

我正在尝试使用 docker-composeSpring Boot 应用程序与其 MariaDB 数据库一起 dockerize 化,但我收到以下错误使用命令“docker-compose up”运行容器

java.sql.SQLNonTransientConnectionException: Could not connect to address=(host=localhost)(port=3306)(type=master) : Connection refused (Connection refused)

服务 api 使用以下 Dockerfile:

FROM java:8
EXPOSE 8080
ADD target/cm-website-0.0.1-SNAPSHOT.jar cm-website.jar
RUN bash -c 'touch /cm-website.jar'
ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "-Dspring.profiles.active=development", "/cm-website.jar"]

我的 docker-compose.yml 文件是:

version: '3'

services:
db:
container_name: backend-mariadb
image: mariadb:latest
environment:
- MYSQL_ROOT_PASSWORD=pass
- MYSQL_DATABASE=cmdb
- MYSQL_USER=cmdb_user
- MYSQL_PASSWORD=pass
ports:
- 3306:3306
api:
container_name: backend-api
image: shaunyl/backend-api
depends_on:
- db
build:
context: .
dockerfile: Dockerfile
ports:
- 8080:8080

我的 application-development.yml 文件是:

spring:
profiles: development
main:
banner-mode: console
jpa:
show-sql: true
generate-ddl: false
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
datasource:
name: ds-dev-mariadb
url: jdbc:mariadb://db:3306/cmdb&useSSL=false
username: cmdb_user
password: pass
driver-class-name: org.mariadb.jdbc.Driver

你知道问题出在哪里吗?谢谢

编辑 1:docker logs backend-mariadb

的输出
2018-08-23 16:15:37 0 [Note] mysqld (mysqld 10.3.9-MariaDB-1:10.3.9+maria~bionic) starting as process 1 ...
2018-08-23 16:15:37 0 [Note] InnoDB: Using Linux native AIO
2018-08-23 16:15:37 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-08-23 16:15:37 0 [Note] InnoDB: Uses event mutexes
2018-08-23 16:15:37 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2018-08-23 16:15:37 0 [Note] InnoDB: Number of pools: 1
2018-08-23 16:15:37 0 [Note] InnoDB: Using SSE2 crc32 instructions
2018-08-23 16:15:37 0 [Note] InnoDB: Initializing buffer pool, total size = 256M, instances = 1, chunk size = 128M
2018-08-23 16:15:37 0 [Note] InnoDB: Completed initialization of buffer pool
2018-08-23 16:15:37 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2018-08-23 16:15:37 0 [Note] InnoDB: 128 out of 128 rollback segments are active.
2018-08-23 16:15:37 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2018-08-23 16:15:37 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2018-08-23 16:15:37 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2018-08-23 16:15:37 0 [Note] InnoDB: 10.3.9 started; log sequence number 1630824; transaction id 21
2018-08-23 16:15:37 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2018-08-23 16:15:37 0 [Note] Plugin 'FEEDBACK' is disabled.
2018-08-23 16:15:37 0 [Note] Server socket created on IP: '::'.
2018-08-23 16:15:37 0 [Warning] 'proxies_priv' entry '@% root@1b6a13ea879f' ignored in --skip-name-resolve mode.
2018-08-23 16:15:37 0 [Note] InnoDB: Buffer pool(s) load completed at 180823 16:15:37
2018-08-23 16:15:37 0 [Note] Reading of all Master_info entries succeded
2018-08-23 16:15:37 0 [Note] Added new Master_info '' to hash table
2018-08-23 16:15:37 0 [Note] mysqld: ready for connections.
Version: '10.3.9-MariaDB-1:10.3.9+maria~bionic' socket: '/var/run/mysqld/mysqld.sock' port: 3306 mariadb.org binary distribution

最佳答案

根据日志,您的服务仍在尝试联系 localhost 但不是 db。你确定你已经重建了你的 JAR 文件和/或 docker 图像吗?可能您的 docker-compose 仍在运行具有旧配置的过时镜像。

请记住,docker-compose up 仅检测您的 docker-compose 文件更改 - 它对您的 JAR 文件或 Dockerfile 更改一无所知。

关于java - 使用 docker-compose 启动 dockerized Spring Boot 和 MariaDb 时出现连接拒绝错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51988866/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com