angular - Docker 容器启动 monorepo 应用程序很慢
问题描述
当我运行 docker-compose 通过 NX 构建 Angular 和 Nest 应用程序的 monorepo 时,构建速度很快,但容器运行速度非常慢。但如果我直接在我的 Mac 上运行这些应用程序,它的构建速度会非常快。我希望应用程序在 docker 中构建得更快。
在我的 docker-compose.yml 中有一个服务示例:
dollop-accounts-web:
command: npm start dollop-accounts-web
build:
args:
- NODE_VERSION=${NODE_VERSION}
- PORT=${ACCOUNTS_WEB_PORT}
context: .
container_name: dollop-accounts-web
image: dollop-node-image
ports:
- ${ACCOUNTS_WEB_PORT}:${ACCOUNTS_WEB_PORT}
volumes:
- .:/usr/src/app
这是我用于所有服务的 dockerfile(请注意,我为每个容器复制了整个 monorepo,因为我不知道如何更好地处理它):
ARG NODE_VERSION
ARG PORT
FROM node:$NODE_VERSION
WORKDIR /usr/src/app
COPY . .
EXPOSE $PORT
我运行 7 个这样的服务,并且我有一个 Nest 应用程序的日志:
> dollop@1.0.0 start /usr/src/app
> nx serve "dollop-accounts-service"
> nx run dollop-accounts-service:serve
Starting type checking service...
Using 2 workers with 2048MB memory limit
而Angular App的这种日志:
> dollop@1.0.0 start /usr/src/app
> nx serve "dollop-tasks-web"
> nx run dollop-tasks-web:serve
WARNING: This is a simple server for use in testing or debugging Angular applications
locally. It hasn't been reviewed for security issues.
Binding this server to an open connection can result in compromising your application or
computer. Using a different host than the one passed to the "--host" flag might result in
websocket connection issues. You might need to use "--disableHostCheck" if that's the
case.
Another process, with id 35, is currently running ngcc.
Waiting up to 250s for it to finish.
(If you are sure no ngcc process is running then you should delete the lock-file at /usr/src/app/node_modules/@angular/compiler-cli/ngcc/__ngcc_lock_file__.)
如您所见,一次启动所有应用程序很困难。但即使只有一项服务,它也比我在主机上运行时要慢得多。有没有办法优化这个?
解决方案
推荐阅读
- c# - ORA-6550 调用中的参数数量错误
- php - 在 Cakephp 中对 PHP foreach() 循环进行排序
- android - 统一构建APK时无法合并android清单
- android - 错误:确保首先调用 FacebookSdk.sdkInitialize()
- python-3.x - 如何在 python 中打印 0 到 100 的素数
- android - StateListAnimator 不在复选框上工作
- javascript - 从 asyncStorage 获取时 JSON.parse(object) 抛出错误:位置 1 处 JSON 中的意外标记 o
- spring-boot - 如何使用 Spring Kafka 测试 Kafka Streams 应用程序?
- python - 如何处理python中的空输入
- javascript - 是否可以修改作为参数传递给类的方法