gpt4 book ai didi

angular - 获取 "The serve command requires to be run in an Angular project, but a project definition could not be found"运行 Docker Compose

转载 作者:行者123 更新时间:2023-12-02 18:27:29 27 4
gpt4 key购买 nike

首先,我通知您,我目前是软件开发专业的学生。所以我请求你对我的问题的宽容:)

我在尝试启动我的 docker-compose 服务时遇到问题。它是 3 个服务 docker-compose.yml:Java 后端、Angular 7 前端、Postgres DB。


[编辑]:Wassim 已找到解决方案。我必须更改服务 ct-front 中的卷 FROM:

volumes:
- '.:/app'

volumes:
- 'contacts-front:/app'

然后将 contacts-front: 添加到我的卷声明中。

volumes:
db_data:
contacts-front:

Back 和 DB 运行良好。但是 Angular 应用程序不起作用。我收到一个非常著名的错误:

cont-ct-front | The serve command requires to be run in an Angular project, but a project definition could not be found.

如果我在我的 Angular 应用程序中运行“ng v”,我会得到以下输出:

Angular CLI: 7.3.7
Node: 12.9.0
OS: win32 x64
Angular: 7.2.11
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.13.7
@angular-devkit/build-angular 0.13.7
@angular-devkit/build-optimizer 0.13.7
@angular-devkit/build-webpack 0.13.7
@angular-devkit/core 7.3.7
@angular-devkit/schematics 7.3.7
@angular/cdk 7.3.6
@angular/cli 7.3.7
@angular/material 7.3.6
@ngtools/webpack 7.3.7
@schematics/angular 7.3.7
@schematics/update 0.13.7
rxjs 6.3.3
typescript 3.2.4
webpack 4.29.0

当然,我尝试了我在google上找到的解决方案是运行

ng update @angular/cli --migrate-only --from=<angular-cli version>

但错误仍然存​​在。

这是我的 docker 配置文件。

docker-compose.yml

version: '3.7'

services:
ct-db:
build:
context: .
dockerfile: Dockerfile-db
container_name: cont-ct-db
restart: unless-stopped
ports:
- 5432:5432
expose:
- 5432
environment:
POSTGRES_USER: admin_ct
POSTGRES_PASSWORD: 123
POSTGRES_DB: db_contacts
volumes:
- db_data:/var/lib/postgres/data
networks:
- ct-network

ct-back:
depends_on:
- ct-db
build:
context: .
dockerfile: Dockerfile-back
container_name: cont-ct-back
ports:
- 8080:8080
expose:
- 8080
environment:
SPRING_DATASOURCE_USERNAME: admin_ct
SPRING_DATASOURCE_PASSWORD: 123
SPRING_DATASOURCE_URL: jdbc:postgresql://ct-db:5432/db_contacts
networks:
- ct-network

ct-front:
build:
context: .
dockerfile: contacts-front/Dockerfile-front
container_name: cont-ct-front
volumes:
- '.:/app'
- '/app/node_modules'
ports:
- 4200:4200
networks:
- ct-network

networks:
ct-network:

volumes:
db_data:

Dockerfile-back

FROM openjdk:8
ADD contacts-back/contacts-back.jar contacts-back.jar
ENTRYPOINT ["java", "-jar", "contacts-back.jar"]

Dockerfile-front

# base image
FROM node:latest

# install chrome for protractor tests
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
RUN apt-get update && apt-get install -yq google-chrome-stable

# set working directory
WORKDIR /app

# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH

# install and cache app dependencies
COPY contacts-front/package.json /app/package.json
RUN npm install
RUN npm install -g @angular/cli@7.3.7

# add app
COPY contacts-front/. /app

# start app
CMD ng serve --host 0.0.0.0

Dockerfile-db

FROM postgres:latest
COPY db/db_data.sql /docker-entrypoint-initdb.d/init.sql
COPY db/db_insert.sql /opt/db_insert.sql
COPY sh/backup-db.sh /opt/backup-db.sh
RUN apt-get update \
&& apt-get install vim -y \
&& export EDITOR=/usr/bin/vim \
&& chmod +x /opt/backup-db.sh \

我的目录树是:

contacts-back       --> directory containing the JAR file
contacts-front --> directory containing the Angular application
db --> directory containing the SQL scripts
sh --> directory containing the SH scripts
docker-compose.yml
Dockerfile-back
Dockerfile-db

要点:如果我将所有 docker 配置文件和脚本放在 Angular 应用程序目录 (contacts-front) 中,Angular 应用程序可以正常工作。但这真的很难看,对吧?

有没有人看到我做错了什么?

像往常一样,非常感谢您的帮助! :)

最佳答案

我认为问题出在“ct-front”卷中提到的主机路径:

volumes:
- 'contacts-front:/app'

关于angular - 获取 "The serve command requires to be run in an Angular project, but a project definition could not be found"运行 Docker Compose,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58222660/

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