programing

도커 컴포지트를 사용하여 도커라이즈된 스프링 부트 및 MariaDb를 시작할 때 Connection Rejected 오류가 발생함

sourcejob 2022. 11. 5. 17:32
반응형

도커 컴포지트를 사용하여 도커라이즈된 스프링 부트 및 MariaDb를 시작할 때 Connection Rejected 오류가 발생함

도킹하려고 합니다.Spring Boot응용 프로그램 및 응용 프로그램MariaDB데이터베이스 사용docker-compose그러나 'docker-compose up' 명령을 사용하여 컨테이너를 실행하면 다음 오류가 발생합니다.

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

service 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하지만 아니다dbJAR 파일 및/또는 도커 이미지를 재구축하시겠습니까?도커 컴포지트가 오래된 구성으로 오래된 이미지를 실행하고 있을 수 있습니다.

주의해 주세요docker-compose up는 도커 컴포지트 파일 변경만 검출하며 JAR 파일 또는 도커 파일 변경에 대해서는 아무것도 인식하지 않습니다.

로컬 호스트가 아닌 연결을 허용하도록 DB를 구성해야 할 것 같습니다.

컨테이너 내에서 /etc/my.cnf 파일을 찾아 skip-networkingbind-address 속성을 코멘트 아웃합니다.

[mysqld]
...
#skip-networking
...
#bind-address = <some ip-address>
...

그런 다음 사용자(또는 원격 연결에 사용할 다른 사용자)에게 액세스 권한을 부여해야 합니다.이 문장은 다음과 같습니다.

PRIVILEGES ON *.* TO 'root'@'192.168.100.%' IDENTIFIED BY 'my-new-password' WITH GRANT OPTION;

상세한 것에 대하여는, https://mariadb.com/kb/en/library/configuring-mariadb-for-remote-client-access/ 를 참조해 주세요.

도움이 됐으면 좋겠다!

언급URL : https://stackoverflow.com/questions/51988866/connection-refused-error-when-starting-dockerized-spring-boot-and-mariadb-with-d

반응형