应用程序启动没有错误,但是当我去站点检查时,所有对数据库的请求都没有给出响应,就好像没有连接一样。
Dockerfile:
FROM eclipse-temurin:17-jdk-alpine
RUN apk add --no-cache mysql-client
WORKDIR /dayzwiki
COPY /target/dayz-wiki-0.0.1-SNAPSHOT.jar /dayzwiki/dayzwiki.jar
ENTRYPOINT ["java", "-jar", "dayzwiki.jar"]
EXPOSE 8080
应用程序-docker.properties:MYSQl
spring.datasource.url=jdbc:mysql://db:3307/dayz_wiki
spring.datasource.username=bestuser
spring.datasource.password=0000
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.ddl-auto=update
spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect
spring.jpa.open-in-view=false
docker-compose.yml:
services:
db:
image: mysql:8.0
container_name: db
ports:
- "3307:3307"
environment:
MYSQL_DATABASE: dayz_wiki
MYSQL_USER: bestuser
MYSQL_PASSWORD: 0000
MYSQL_ROOT_PASSWORD: 0000
MYSQL_TCP_PORT: 3307
command: --port=3307
volumes:
- db_data:/var/lib/mysql
healthcheck:
test: ["CMD-SHELL", "mysqladmin ping -h 127.0.0.1 --silent"]
interval: 10s
timeout: 5s
retries: 5
app:
depends_on:
db:
condition: service_healthy
build:
context: .
dockerfile: Dockerfile
container_name: java-container
ports:
- "8080:8080"
environment:
SPRING_DATASOURCE_URL: jdbc:mysql://db:3307/dayz_wiki
SPRING_DATASOURCE_USERNAME: bestuser
SPRING_DATASOURCE_PASSWORD: 0000
volumes:
db_data:
日志:
PS D:\DayZ-Wiki> docker-compose up --build
[+] Running 1/1
✔ db Pulled 1.4s
[+] Building 3.1s (11/11) FINISHED docker:desktop-linux
=> [app internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 253B 0.0s
=> [app internal] load metadata for docker.io/library/eclipse-temurin:17-jdk-alpine 1.4s
=> [app auth] library/eclipse-temurin:pull token for registry-1.docker.io 0.0s
=> [app internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [app 1/4] FROM docker.io/library/eclipse-temurin:17-jdk-alpine@sha256:4708e1a2c3baa0855eb9b3e6ae6285c8640d574c25ba74fddf6b8a17ccc3673f 0.1s
=> => resolve docker.io/library/eclipse-temurin:17-jdk-alpine@sha256:4708e1a2c3baa0855eb9b3e6ae6285c8640d574c25ba74fddf6b8a17ccc3673f 0.1s
=> [app internal] load build context 0.0s
=> => transferring context: 85B 0.0s
=> CACHED [app 2/4] RUN apk add --no-cache mysql-client 0.0s
=> CACHED [app 3/4] WORKDIR /dayzwiki 0.0s
=> CACHED [app 4/4] COPY /target/dayz-wiki-0.0.1-SNAPSHOT.jar /dayzwiki/dayzwiki.jar 0.0s
=> [app] exporting to image 1.3s
=> => exporting layers 0.0s
=> => exporting manifest sha256:c4f66e38a382c90d526a4f84ecab8316c0ced0927fd5eaf7952a3bc0bb1e1b53 0.0s
=> => exporting config sha256:214304ae1b9391be9413994370396d5930da0fbd400e3c754fe0847139b7a993 0.0s
=> => exporting attestation manifest sha256:068c5cf2b219aa23e6e583ea74d1a027832674703596229dc95df66bfa98f3e6 0.1s
=> => exporting manifest list sha256:56e34bea99397df46b18eb37a8d06bd4729d65b2a37b74f731473e9a687c74e6 0.0s
=> => naming to docker.io/library/dayz-wiki-app:latest 0.0s
=> => unpacking to docker.io/library/dayz-wiki-app:latest 1.1s
=> [app] resolving provenance for metadata file 0.0s
[+] Running 4/4
✔ Network dayz-wiki_default Created 0.1s
✔ Volume "dayz-wiki_db_data" Created 0.0s
✔ Container db Created 3.9s
✔ Container java-container Created 0.2s
Attaching to db, java-container
db | 2024-12-08 22:13:59+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.40-1.el9 started.
db | 2024-12-08 22:13:59+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
db | 2024-12-08 22:13:59+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.40-1.el9 started.
db | 2024-12-08 22:13:59+00:00 [Note] [Entrypoint]: Initializing database files
db | 2024-12-08T22:13:59.706542Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
db | 2024-12-08T22:13:59.706629Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.40) initializing of server in progress as process 81
db | 2024-12-08T22:13:59.715220Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
db | 2024-12-08T22:14:00.558965Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
db | 2024-12-08T22:14:02.339328Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
db | 2024-12-08 22:14:08+00:00 [Note] [Entrypoint]: Database files initialized
db | 2024-12-08 22:14:08+00:00 [Note] [Entrypoint]: Starting temporary server
db | 2024-12-08T22:14:08.476904Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
db | 2024-12-08T22:14:08.477936Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.40) starting as process 125
db | 2024-12-08T22:14:08.491809Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
db | 2024-12-08T22:14:08.946020Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
db | 2024-12-08T22:14:09.338457Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
db | 2024-12-08T22:14:09.338505Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
db | 2024-12-08T22:14:09.351821Z 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 | 2024-12-08T22:14:09.382540Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: /var/run/mysqld/mysqlx.sock
db | 2024-12-08T22:14:09.382657Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.40' socket: '/var/run/mysqld/mysqld.sock' port: 0 MySQL Community Server - GPL.
db | 2024-12-08 22:14:09+00:00 [Note] [Entrypoint]: Temporary server started.
db | '/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
db | Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
db | Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
db | Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.
db | Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.
db | Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
db | Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
db | 2024-12-08 22:14:11+00:00 [Note] [Entrypoint]: Creating database dayz_wiki
db | 2024-12-08 22:14:11+00:00 [Note] [Entrypoint]: Creating user bestuser
db | 2024-12-08 22:14:11+00:00 [Note] [Entrypoint]: Giving user bestuser access to schema dayz_wiki
db |
db | 2024-12-08 22:14:11+00:00 [Note] [Entrypoint]: Stopping temporary server
db | 2024-12-08T22:14:11.830862Z 13 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.40).
db | 2024-12-08T22:14:14.279776Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.40) MySQL Community Server - GPL.
db | 2024-12-08 22:14:14+00:00 [Note] [Entrypoint]: Temporary server stopped
db |
db | 2024-12-08 22:14:14+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
db |
db | 2024-12-08T22:14:15.034923Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
db | 2024-12-08T22:14:15.036371Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.40) starting as process 1
db | 2024-12-08T22:14:15.044724Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
db | 2024-12-08T22:14:15.585171Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
db | 2024-12-08T22:14:16.059497Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
db | 2024-12-08T22:14:16.059565Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
db | 2024-12-08T22:14:16.069027Z 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 | 2024-12-08T22:14:16.105519Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
db | 2024-12-08T22:14:16.105611Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.40' socket: '/var/run/mysqld/mysqld.sock' port: 3307 MySQL Community Server - GPL.
java-container | SLF4J(W): Class path contains multiple SLF4J providers.
java-container | SLF4J(W): Found provider [ch.qos.logback.classic.spi.LogbackServiceProvider@69d9c55]
java-container | SLF4J(W): Found provider [org.slf4j.simple.SimpleServiceProvider@13a57a3b]
java-container | SLF4J(W): See https://www.slf4j.org/codes.html#multiple_bindings for an explanation.
java-container | SLF4J(I): Actual provider is of type [ch.qos.logback.classic.spi.LogbackServiceProvider@69d9c55]
java-container |
java-container | . ____ _ __ _ _
java-container | /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
java-container | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
java-container | \\/ ___)| |_)| | | | | || (_| | ) ) ) )
java-container | ' |____| .__|_| |_|_| |_\__, | / / / /
java-container | =========|_|==============|___/=/_/_/_/
java-container | :: Spring Boot :: (v3.2.5)
java-container |
java-container | 2024-12-08T22:14:21.387Z INFO 1 --- [DayZWiki] [ main] c.dayzwiki.portal.DayzWikiApplication : Starting DayzWikiApplication v0.0.1-SNAPSHOT using Java 17.0.13 with PID 1 (/dayzwiki/dayzwiki.jar started by root in /dayzwiki)
java-container | 2024-12-08T22:14:21.390Z INFO 1 --- [DayZWiki] [ main] c.dayzwiki.portal.DayzWikiApplication : The following 1 profile is active: "local"
java-container | 2024-12-08T22:14:22.430Z INFO 1 --- [DayZWiki] [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
java-container | 2024-12-08T22:14:22.579Z INFO 1 --- [DayZWiki] [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 139 ms. Found 18 JPA repository interfaces.
java-container | 2024-12-08T22:14:23.338Z INFO 1 --- [DayZWiki] [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port 8080 (http)
java-container | 2024-12-08T22:14:23.352Z INFO 1 --- [DayZWiki] [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
java-container | 2024-12-08T22:14:23.352Z INFO 1 --- [DayZWiki] [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.20]
java-container | 2024-12-08T22:14:23.402Z INFO 1 --- [DayZWiki] [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
java-container | 2024-12-08T22:14:23.403Z INFO 1 --- [DayZWiki] [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1906 ms
java-container | 2024-12-08T22:14:23.580Z INFO 1 --- [DayZWiki] [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
java-container | 2024-12-08T22:14:23.645Z INFO 1 --- [DayZWiki] [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 6.4.4.Final
java-container | 2024-12-08T22:14:23.692Z INFO 1 --- [DayZWiki] [ main] o.h.c.internal.RegionFactoryInitiator : HHH000026: Second-level cache disabled
java-container | 2024-12-08T22:14:23.953Z INFO 1 --- [DayZWiki] [ main] o.s.o.j.p.SpringPersistenceUnitInfo : No LoadTimeWeaver setup: ignoring JPA class transformer
java-container | 2024-12-08T22:14:23.993Z INFO 1 --- [DayZWiki] [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
java-container | 2024-12-08T22:14:24.310Z INFO 1 --- [DayZWiki] [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection com.mysql.cj.jdbc.ConnectionImpl@44aeae34
java-container | 2024-12-08T22:14:24.312Z INFO 1 --- [DayZWiki] [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
java-container | 2024-12-08T22:14:25.591Z INFO 1 --- [DayZWiki] [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000489: No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration)
java-container | 2024-12-08T22:14:30.067Z INFO 1 --- [DayZWiki] [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
java-container | 2024-12-08T22:14:30.748Z WARN 1 --- [DayZWiki] [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
java-container | 2024-12-08T22:14:31.210Z INFO 1 --- [DayZWiki] [ main] o.s.s.web.DefaultSecurityFilterChain : Will secure any request with [org.springframework.security.web.session.DisableEncodeUrlFilter@62a78446, org.springframework.security.web.c
ontext.request.async.WebAsyncManagerIntegrationFilter@5a919251, org.springframework.security.web.context.SecurityContextHolderFilter@2da3d7d3, org.springframework.security.web.header.HeaderWriterFilter@2b33e616, org.springframework.security.web.authentication.logou
t.LogoutFilter@42af2977, com.dayzwiki.portal.security.JwtAuthenticationFilter@40612056, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@47184859, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@22781286, org
.springframework.security.web.authentication.AnonymousAuthenticationFilter@33a0b857, org.springframework.security.web.session.SessionManagementFilter@5f7dbdfa, org.springframework.security.web.access.ExceptionTranslationFilter@175c4ae5, org.springframework.security.web.access.intercept.AuthorizationFilter@5d6cac57]
java-container | 2024-12-08T22:14:31.952Z INFO 1 --- [DayZWiki] [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port 8080 (http) with context path ''
java-container | 2024-12-08T22:14:31.975Z INFO 1 --- [DayZWiki] [ main] c.dayzwiki.portal.DayzWikiApplication : Started DayzWikiApplication in 11.106 seconds (process running for 11.659)
我尝试过的:
- 更改MySQL端口(3306正忙)
- 连接数据库bestuser和root,在控制台中写道:
C:\Windows\system32>docker exec -it db sh
sh-5.1# mysql -u bestuser -p
Enter password:
ERROR 1045 (28000): Access denied for user 'bestuser'@'localhost' (using password: YES)