我正在使用JIB构建我的Java Docker镜像并将其推送到我的仓库中。
问题:
1.当我拉取镜像并尝试从该镜像运行容器时,它显示在目录中找不到docker compose文件。
- docker桌面中的container正在阻止启动(状态:restarting)
我正在添加我的docker-compose.yml文件和docker日志的图像:
java.lang.IllegalStateException: No Docker Compose file found in directory '/.'
at org.springframework.util.Assert.state(Assert.java:97) ~[spring-core-6.0.11.jar:6.0.11]
at org.springframework.boot.docker.compose.lifecycle.DockerComposeLifecycleManager.getComposeFile(DockerComposeLifecycleManager.java:140) ~[spring-boot-docker-compose-3.1.2.jar:3.1.2]
at org.springframework.boot.docker.compose.lifecycle.DockerComposeLifecycleManager.start(DockerComposeLifecycleManager.java:108) ~[spring-boot-docker-compose-3.1.2.jar:3.1.2]
at org.springframework.boot.docker.compose.lifecycle.DockerComposeListener.onApplicationEvent(DockerComposeListener.java:53) ~[spring-boot-docker-compose-3.1.2.jar:3.1.2]
at org.springframework.boot.docker.compose.lifecycle.DockerComposeListener.onApplicationEvent(DockerComposeListener.java:35) ~[spring-boot-docker-compose-3.1.2.jar:3.1.2]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-6.0.11.jar:6.0.11]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-6.0.11.jar:6.0.11]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) ~[spring-context-6.0.11.jar:6.0.11]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131) ~[spring-context-6.0.11.jar:6.0.11]
at org.springframework.boot.context.event.EventPublishingRunListener.multicastInitialEvent(EventPublishingRunListener.java:136) ~[spring-boot-3.1.2.jar:3.1.2]
at org.springframework.boot.context.event.EventPublishingRunListener.contextLoaded(EventPublishingRunListener.java:98) ~[spring-boot-3.1.2.jar:3.1.2]
at org.springframework.boot.SpringApplicationRunListeners.lambda$contextLoaded$4(SpringApplicationRunListeners.java:72) ~[spring-boot-3.1.2.jar:3.1.2]
at java.base/java.lang.Iterable.forEach(Iterable.java:75) ~[na:na]
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:118) ~[spring-boot-3.1.2.jar:3.1.2]
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:112) ~[spring-boot-3.1.2.jar:3.1.2]
at org.springframework.boot.SpringApplicationRunListeners.contextLoaded(SpringApplicationRunListeners.java:72) ~[spring-boot-3.1.2.jar:3.1.2]
at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:416) ~[spring-boot-3.1.2.jar:3.1.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:311) ~[spring-boot-3.1.2.jar:3.1.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-3.1.2.jar:3.1.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-3.1.2.jar:3.1.2]
at com.amigoes.fullstack.FullstackApplication.main(FullstackApplication.java:18) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:50) ~[spring-boot-devtools-3.1.2.jar:3.1.2]
字符串
docker文件:
services:
db:
container_name: postgres
image: postgres
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: 123456789
PGDATA: /data/postgres
volumes:
- db:/data/postgres
ports:
- "5433:5432"
networks:
- db
restart: unless-stopped
fullstack-api:
container_name: fullstack-api
image: ahmadmujtaba200210/fullstack
environment:
SPRING_DATASOURCE_URL: "jdbc:postgresql://db:5432/customer"
ports:
- "8088:8080"
networks:
- db
depends_on:
- db
restart: unless-stopped
networks:
db:
driver: bridge
volumes:
db:
型
我的应用程序.yml文件:
server:
error:
include-message: always
port: 8080
spring:
datasource:
url: jdbc:postgresql://localhost:5433/customer
driver-class-name: org.postgresql.Driver
password: 123456789
username: postgres
jpa:
hibernate:
ddl-auto: none
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
format_sql: true
show_sql: true
main:
web-application-type: servlet
docker:
compose:
file: ./docker-compose.yaml
型
docker desktop showing status of containers
发现了一些有趣的希望,所以你可能会看到一些帮助,在解决我的这个问题,因为我是新的docker。
vulnerbility的
我的docker文件在那里,但我的代码仍然没有运行。我正在使用Sping Boot ,docker,postgres和Jib
我已经尝试了google或spring guidlines上给出的每一种文件命名格式:
1../docker/composite.yml(将合成文件移动到单独的文件夹中)
1../docker-compose.yaml
1../docker-compose.yml
2条答案
按热度按时间nfg76nw01#
在您的application.properties set
spring.docker.compose.enabled=false
.中,当您构建和编译映像并推送到dockerHub时,docker-compose.yml不包含在内,因此您在编译代码时会遇到错误mbzjlibv2#
尝试运行Docker Compose设置,而不将其嵌入Sping Boot 应用程序中。通常,您会使用Docker Compose从主机启动服务。
使用
docker-compose up
启动您的服务并检查是否有任何错误。确保您的应用程序在尝试连接之前等待数据库完全准备好。如果您的应用程序在数据库准备好之前启动,它可能会崩溃并不断重新启动。有一些工具,如wait-for-it和dockerize,可以帮助解决这个问题。
以下是你可以做的:
**删除Docker编写依赖项:**在
pom.xml
或build.gradle
中,查找与spring-boot-docker-compose
相关的依赖项并将其删除。**删除配置:**在Sping Boot
application.yml
或application.properties中,查找与Docker Compose相关的任何配置属性,如spring.docker.compose.file
,并将其删除。检查您的主应用类:在
FullstackApplication.java
中(或您的主Sping Boot 应用类所在的任何地方),确保您没有任何Docker Compose相关的bean或配置。删除您发现的任何beans或配置。**重新构建和重新启动:**完成这些更改后,请重新构建Sping Boot 应用程序并重新启动Docker Compose安装程序。
**检查日志:**重启后,再次检查
fullstack-api
容器的日志,确保错误已解决。请记住,当您在Sping Boot 应用程序外部使用Docker Compose时,您不希望Sping Boot 应用程序内部有任何Docker Compose相关逻辑。两者应该独立运行。