gpt4 book ai didi

mysql - 为什么我的应用程序无法连接到 mysql?

转载 作者:行者123 更新时间:2023-11-29 15:39:12 27 4
gpt4 key购买 nike

我做了 docker-compose,但我的应用程序不想连接到数据库。可能是什么问题呢?应用程序本身启动得很好,但是一旦我把它变成容器,它就无法连接到数据库,并且出现很多错误。

docker-compose:

version: '3.7'

services:

db:
image: mysql:8.0.17
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: 123test321
ports:
- 3306:3306
networks:
- employee-mysql
volumes:
- /home/alexey/temp/mysql01:/var/lib/mysql

adminer:
image: adminer
restart: always
ports:
- 3380:8080

webapp:
build:
context: .
restart: always
ports:
- 80:8080
networks:
- employee-mysql
depends_on:
- db

networks:
employee-mysql:

这是 dockerfile:

FROM anapsix/alpine-java:8_jdk

FROM openjdk:8
ADD target/webapp-1.0.1.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]

这是我的日志:

    Starting work_db_1      ... done
Starting work_adminer_1 ... done
Starting work_webapp_1 ... done
Attaching to work_db_1, work_adminer_1, work_webapp_1
db_1 | 2019-09-09T17:29:20.983653Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
db_1 | 2019-09-09T17:29:20.983965Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.17) starting as process 1
db_1 | 2019-09-09T17:29:22.697164Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
db_1 | 2019-09-09T17:29:22.704622Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
db_1 | 2019-09-09T17:29:22.807613Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.17' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
db_1 | 2019-09-09T17:29:23.019957Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060
adminer_1 | PHP 7.3.9 Development Server started at Mon Sep 9 17:29:21 2019
webapp_1 | [INFO ] 2019-09-09 17:29:30.149 [main] ApplicationKt - Starting ApplicationKt v1.0.1 on d52aa0a7ff7e with PID 1 (/app.jar started by root in /)
webapp_1 | [INFO ] 2019-09-09 17:29:30.184 [main] ApplicationKt - No active profile set, falling back to default profiles: default
webapp_1 | [INFO ] 2019-09-09 17:29:38.634 [main] RepositoryConfigurationDelegate - Bootstrapping Spring Data repositories in DEFAULT mode.
webapp_1 | [INFO ] 2019-09-09 17:29:39.562 [main] RepositoryConfigurationDelegate - Finished Spring Data repository scanning in 894ms. Found 19 repository interfaces.
webapp_1 | [INFO ] 2019-09-09 17:29:42.756 [main] PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$e8bed525] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
webapp_1 | [INFO ] 2019-09-09 17:29:43.087 [main] PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration' of type [org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration$$EnhancerBySpringCGLIB$$816c9d5f] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
webapp_1 | [INFO ] 2019-09-09 17:29:43.130 [main] PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'objectPostProcessor' of type [org.springframework.security.config.annotation.configuration.AutowireBeanFactoryObjectPostProcessor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
webapp_1 | [INFO ] 2019-09-09 17:29:43.139 [main] PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler@7d61eb55' of type [org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
webapp_1 | [INFO ] 2019-09-09 17:29:43.159 [main] PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration' of type [org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration$$EnhancerBySpringCGLIB$$a6414011] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
webapp_1 | [INFO ] 2019-09-09 17:29:43.202 [main] PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.security.config.annotation.method.configuration.Jsr250MetadataSourceConfiguration' of type [org.springframework.security.config.annotation.method.configuration.Jsr250MetadataSourceConfiguration$$EnhancerBySpringCGLIB$$cb965827] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
webapp_1 | [INFO ] 2019-09-09 17:29:43.237 [main] PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'jsr250MethodSecurityMetadataSource' of type [org.springframework.security.access.annotation.Jsr250MethodSecurityMetadataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
webapp_1 | [INFO ] 2019-09-09 17:29:43.244 [main] PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'methodSecurityMetadataSource' of type [org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
webapp_1 | [INFO ] 2019-09-09 17:29:45.329 [main] HikariDataSource - HikariPool-1 - Starting...
webapp_1 | [ERROR] 2019-09-09 17:29:46.161 [main] HikariPool - HikariPool-1 - Exception during pool initialization.
webapp_1 | com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
webapp_1 |
webapp_1 | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

最佳答案

好吧。

version: '3.7'

services:

db:
image: mysql:8.0.17
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: ****
ports:
- 3306:3306
volumes:
- /home/alexey/temp/mysql01:/var/lib/mysql

adminer:
image: adminer
restart: always
ports:
- 3380:8080

webapp:
build:
context: .
environment:
CONTEXT_PATH: /a-test
DB_HOST: db
DB_PORT: 3306
DB_NAME: ****
DB_USER: ****
DB_PASSWORD: ****
MAIL_LOGIN: ****
MAIL_PASSWORD: ****
ports:
- 80:8080
depends_on:
- db

和 Dockerfile:

FROM anapsix/alpine-java:8_jdk

FROM openjdk:8

ADD target/webapp-*.jar webapp.jar

EXPOSE 8080

ENTRYPOINT java -jar webapp.jar

关于mysql - 为什么我的应用程序无法连接到 mysql?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57858766/

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