gpt4 book ai didi

java - Docker-compose:/app.war 中没有主要 list 属性

转载 作者:行者123 更新时间:2023-12-02 08:51:44 24 4
gpt4 key购买 nike

我正在尝试容器化我的 Spring Boot 应用程序,但是我遇到了 docker 问题...

docker-compose build
db uses an image, skipping
Building drools-average-docker-app
Step 1/5 : FROM java:8
---> d23bdf5b1b1b
Step 2/5 : VOLUME /tmp
---> Using cache
---> 6bbb9078c3f0
Step 3/5 : ADD target/DroolsAverage-0.0.1-SNAPSHOT.war DroolsAverage.war
---> 8a01751a6ac9
Step 4/5 : RUN bash -c 'touch /DroolsAverage.war'
---> Running in 330ed2275089
Removing intermediate container 330ed2275089
---> 65cf51ebf28f
Step 5/5 : ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/DroolsAverage.war"]
---> Running in 65357cc5afed
Removing intermediate container 65357cc5afed
---> acb6358e4c0e
Successfully built acb6358e4c0e
Successfully tagged drools-average-docker-image:latest

然后运行docker-compose up会产生以下错误

Recreating droolsaverage_drools-average-docker-app_1_2d763cdbed6c ... done
Starting droolsaverage_db_1_efa205bdb880 ... done
Attaching to droolsaverage_db_1_efa205bdb880, droolsaverage_drools-average-docker-app_1_2d763cdbed6c
db_1_efa205bdb880 | 2018-11-15 21:54:13.781 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
db_1_efa205bdb880 | 2018-11-15 21:54:13.781 UTC [1] LOG: listening on IPv6 address "::", port 5432
db_1_efa205bdb880 | 2018-11-15 21:54:13.795 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1_efa205bdb880 | 2018-11-15 21:54:13.827 UTC [18] LOG: database system was shut down at 2018-11-15 21:51:44 UTC
db_1_efa205bdb880 | 2018-11-15 21:54:13.837 UTC [1] LOG: database system is ready to accept connections
drools-average-docker-app_1_2d763cdbed6c | no main manifest attribute, in /DroolsAverage.war
droolsaverage_drools-average-docker-app_1_2d763cdbed6c exited with code 1

我不明白为什么它说我没有主要 list 属性?

这是我的Main.java

package com.techgap.droolsaverage.droolsaverage;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;


@SpringBootApplication
@ComponentScan (basePackages = {
"com.techgap.droolsaverage.controller",
"com.techgap.droolsaverage.model",
"com.techgap.droolsaverage.util",
"com.techgap.droolsaverage.config",
"com.techgap.droolsaverage.exception"
})
public class Main{

@SuppressWarnings("unused")
private static ConfigurableApplicationContext ctx;
@SuppressWarnings("unused")
private int maxUploadSizeInMb = 10 * 1024 * 1024; // 10 MB

public static void main(String[] argv) {

SpringApplication.run(Main.class, argv);
}
}

我的docker-compose.ymlDockerfile

version: '3.1'

services:
drools-average-docker-app:
image: drools-average-docker-image
build:
context: ./
dockerfile: Dockerfile
ports:
- 8080:8080
db:
image: postgres:11-alpine
environment:
POSTGRES_DB: 'droolsTestDB'
POSTGRES_USER: 'postgres'
POSTGRES_PASSWORD: 'postgres'
ports:
- "5432:5432"
~

和 Dockerfile

FROM java:8
VOLUME /tmp
ADD target/DroolsAverage-0.0.1-SNAPSHOT.war DroolsAverage.war
RUN bash -c 'touch /DroolsAverage.war'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/DroolsAverage.war"]

有人能给我指出正确的方向吗?

最佳答案

如果您打算将应用程序作为独立应用程序运行,请将其打包为 jar 文件而不是 war 文件。打包为 war 文件意味着您将其部署到 Web 服务器(例如 Tomcat),因此 java -jar 选项将不起作用。

关于java - Docker-compose:/app.war 中没有主要 list 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53328497/

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