【问题标题】:Issues building a spring boot application from within a Dockerfile on Linux从 Linux 上的 Dockerfile 中构建 Spring Boot 应用程序的问题
【发布时间】:2020-12-21 18:06:45
【问题描述】:

我在 Linux 上从 Dockerfile 中构建 Spring Boot 应用程序时遇到了困难。

它在 Windows 上运行良好。

我看过其他帖子,人们说我应该在 pom.xml 文件中指定或删除 relativePath,但我认为这不是问题所在,也没有奏效。

这是我的错误,后面是我的代码:

> Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/2.1.1.RELEASE/spring-boot-starter-parent-2.1.1.RELEASE.pom
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for com.ciee:stanfordcorenlp-server:0.0.1-SNAPSHOT: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.1.1.RELEASE from/to central (https://repo.maven.apache.org/maven2): Transfer failed for https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/2.1.1.RELEASE/spring-boot-starter-parent-2.1.1.RELEASE.pom and 'parent.relativePath' points at no local POM @ line 6, column 13
 @
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR]   The project com.ciee:stanfordcorenlp-server:0.0.1-SNAPSHOT (/home/app/pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM for com.ciee:stanfordcorenlp-server:0.0.1-SNAPSHOT: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.1.1.RELEASE from/to central (https://repo.maven.apache.org/maven2): Transfer failed for https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/2.1.1.RELEASE/spring-boot-starter-parent-2.1.1.RELEASE.pom and 'parent.relativePath' points at no local POM @ line 6, column 13: Connect to repo.maven.apache.org:443 [repo.maven.apache.org/199.232.196.215, repo.maven.apache.org/199.232.192.215] failed: Connection timed out (Connection timed out) -> [Help 2]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException
ERROR: Service 'web' failed to build: The command '/bin/sh -c /home/app/with-proxy.sh mvn -f /home/app/pom.xml clean test package' returned a non-zero code: 1

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    
    <groupId>com.ciee</groupId>
    <artifactId>stanfordcorenlp-server</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>stanfordcorenlp-server</name>
    <description>Stanford Core NLP Server</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20180813</version>
        </dependency>

        <dependency>
            <groupId>edu.stanford.nlp</groupId>
            <artifactId>stanford-corenlp</artifactId>
            <version>4.0.0</version>
        </dependency>

        <dependency>
            <groupId>edu.stanford.nlp</groupId>
            <artifactId>stanford-corenlp</artifactId>
            <version>4.0.0</version>
            <classifier>models</classifier>
        </dependency>

        <dependency>
            <groupId>edu.stanford.nlp</groupId>
            <artifactId>stanford-corenlp</artifactId>
            <version>4.0.0</version>
            <classifier>models-english</classifier>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>    
</project>

docker-compose.yml

version: "3"

services:
  web:
      build: 
          context:  ..
          dockerfile: ./docker/Dockerfile.cambridge
      image: stanfordcorenlp  # (override the name Compose picks)
      container_name: stanfordcorenlp
      ports:
        - "9000:9000"
      networks:
        - cieenetwork
networks:
  cieenetwork:
    external: true

Dockerfile:

# build stage
FROM maven:3.6.3-jdk-8 AS build

MAINTAINER Philips CIEE Team

ENV TZ=US/Central
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezon
ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1

COPY ./stanfordcorenlp-server/src /home/app/src
COPY ./stanfordcorenlp-server/pom.xml /home/app

RUN chmod -R 775 /home/app
RUN mvn -f /home/app/pom.xml clean test package



# Package stage
FROM openjdk:8-jdk-alpine

ENV TZ=US/Central
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezon

# set environment variable to log messages immediately
ENV PYTHONUNBUFFERED 1
# set environment variable to prevent Python from writing pyc files to disc (equivalent to python -B option)
ENV PYTHONDONTWRITEBYTECODE 1

COPY --from=build /home/app/target/*.jar app.jar
ENV PORT 9000
EXPOSE 9000
ENTRYPOINT ["java","-jar","app.jar"]

【问题讨论】:

  • 您的 Pom 结构已损坏。检查堆栈跟踪中的原因。
  • 我相信 pom 很好 - 可以在 Dockerfile 中的 Windows 上工作或独立运行。
  • 尝试清理 .m2/repo 并重新构建。
  • 您的 linux 机器无法连接到 repo.maven.apache.org 检查网络连接。正如 maven 日志所说 failed: Connection timed out (Connection timed out)
  • 我可以使用 curl 访问该文件,但不能通过 maven(或 ping 或 traceroute)

标签: java spring-boot docker


【解决方案1】:

我必须设置 Maven 代理设置。 Maven proxy config

【讨论】:

    猜你喜欢
    • 2021-09-26
    • 2019-07-24
    • 2021-05-03
    • 2021-01-07
    • 2020-10-19
    • 2020-07-13
    • 2018-06-20
    • 2022-01-07
    • 1970-01-01
    相关资源
    最近更新 更多