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__.)

如您所见,它很难一次启动所有应用程序。但是,即使只有一项服务,它的运行速度也比在主机上运行时要慢。有没有优化的方法

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)