简体   繁体   中英

Issues building a spring boot application from within a Dockerfile on Linux

I'm having difficulty building a spring boot application from within a Dockerfile on Linux.

It works just fine on Windows.

I've seen other posts where folks say I should specify or remove the relativePath in the pom.xml file, but I don't think that's the issue nor did it work.

Here's my error, followed by my code:

> 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"]

I had to set up maven proxy settings. Maven proxy config

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM