简体   繁体   English

在 docker 容器中运行“ng build”给出“找不到项目定义”

[英]Running "ng build" in docker container gives "project definition could not be found"

I'm trying to build an Angular + Spring-boot project using Maven and deploy it as a docker container.我正在尝试使用 Maven 构建一个 Angular + Spring-boot 项目并将其部署为 docker 容器。 To compile the application I run编译我运行的应用程序

mvn package

which at some point runs ng build .在某些时候运行ng build It works as intended when I do it on my local machine.当我在本地机器上执行时,它按预期工作。 But when I copy files into a docker image and try to run mvn package , I get an error但是当我将文件复制到 docker 图像并尝试运行mvn package时,出现错误

[INFO] --- frontend-maven-plugin:1.11.2:npm (npm-build) @ tradingSandbox ---
[INFO] Running 'npm run-script build' in /
[INFO] 
[INFO] > trading-sandbox@0.0.0 build /
[INFO] > ng build
[INFO] 
[INFO] The build command requires to be run in an Angular project, but a project definition could not be found.
[INFO] npm ERR! code ELIFECYCLE
[INFO] npm ERR! errno 1
[INFO] npm ERR! trading-sandbox@0.0.0 build: `ng build`
[INFO] npm ERR! Exit status 1
[INFO] npm ERR! 
[INFO] npm ERR! Failed at the trading-sandbox@0.0.0 build script.
[INFO] npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
[INFO] 
[INFO] npm ERR! A complete log of this run can be found in:
[INFO] npm ERR!     /root/.npm/_logs/2021-02-23T09_15_24_641Z-debug.log
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

The root directory contains proper angular.json file and Maven downloads correct version of nodejs.根目录包含正确的angular.json文件和 Maven 下载正确版本的 nodejs。 Because it is inside a docker image, I am unable to access debug.log .因为它在 docker 图像中,所以我无法访问debug.log Needless to say I am unexperienced with using a Docker.不用说我没有使用 Docker 的经验。

Dockerfile Dockerfile

FROM maven:3.6.3-jdk-11

COPY . /

RUN cd /
RUN ls -a

ENV PORT=8080

RUN mvn package

CMD mvn spring-boot:run -Dspring-boot.run.profiles=$PROFILE -Dserver.port=$PORT

pom.xml pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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 https://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.4.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>tradingSandbox</artifactId>
    <version>0.0.1</version>
    <name>tradingSandbox</name>
    <description>Trading sandbox</description>
    <properties>
        <java.version>11</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <!--    Database controller for deployment  -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>

<!--    Database controller for testing -->
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>

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

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

        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt-api</artifactId>
            <version>0.10.7</version>
        </dependency>

        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt-impl</artifactId>
            <version>0.10.7</version>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt-jackson</artifactId>
            <version>0.10.7</version>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>
    </resources>

        <plugins>

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

            <plugin>
        <groupId>com.github.eirslett</groupId>
        <artifactId>frontend-maven-plugin</artifactId>
        <version>1.11.2</version>
                <configuration>
                    <nodeVersion>v12.18.4</nodeVersion>
                </configuration>
                <executions>

                    <execution>
                        <id>install-npm</id>
                        <goals>
                            <goal>install-node-and-npm</goal>
                        </goals>
                    </execution>

                    <execution>
                        <id>npm-install</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                    </execution>

          <execution>
            <id>npm-build</id>
            <goals>
              <goal>npm</goal>
            </goals>
            <configuration>
              <arguments>run-script build</arguments>
            </configuration>
          </execution>

                </executions>
            </plugin>

        </plugins>
    </build>

</project>

You are in the wrong directory.您在错误的目录中。 It can not find the angular.json file.它找不到angular.json文件。

remove消除

RUN cd /

from your dockerfile.来自您的 dockerfile。

Make sure that RUN ls -a returns the directory which holds angular.json , and if it doesn't, configure RUN cd blabla correctly.确保RUN ls -a返回包含angular.json的目录,如果没有,请正确配置RUN cd blabla

Got the same issue today.今天遇到同样的问题。 Even though RUN ls -la gave me the correct directory, setting an explicit WORKDIR fixed it for me即使RUN ls -la给了我正确的目录,设置一个明确的WORKDIR为我修复了它

WORKDIR /var/www

I put this as the second line in my Dockerfile after the FROM... line.我把它作为我的 Dockerfile 中FROM...行之后的第二行。 The directory shouldn't matter as WORKDIR creates it if it doesn't exist.该目录无关紧要,因为如果它不存在, WORKDIR会创建它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当从angular文档下载项目并运行ng serve -o项目定义时找不到 - when download project from angular docs and running ng serve -o project definition could not be found 运行 Docker 编写“服务命令需要在 Angular 项目中运行,但找不到项目定义” - Getting “The serve command requires to be run in an Angular project, but a project definition could not be found” running Docker Compose 构建命令需要在Angular项目中运行,但是找不到项目定义 - The build command requires to be run in an Angular project, but a project definition could not be found 运行ng test时在项目中找不到配置 - Configuration could not be found in project when running ng test 项目定义无法找到 - Angular - project definition could not be found— Angular ng serve 命令需要在 Angular 项目中运行,但找不到项目定义 - ng serve command requires to be run in an Angular project, but a project definition could not be found Angular ng serve 不起作用:Serve 命令需要在 Angular 项目中运行,但找不到项目定义 - Angular ng serve not work:The serve command requires to be run in an Angular project, but a project definition could not be found ng serve 抛出错误“服务命令需要在 Angular 项目中运行,但找不到项目定义” - ng serve throws error "The serve command requires to be run in an Angular project, but a project definition could not be found" ng build --prod在Docker容器上不起作用 - ng build --prod not working on Docker container serve命令需要在Angular项目中运行,但是找不到项目定义 - The serve command required to be run in an Angular project, but a project definition could not be found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM