简体   繁体   English

如何使用 NX(反应和节点应用程序)进行 dockerize?

[英]How to dockerize with NX (react and node app)?

I have created a nx workspace with 2 react app (client/admin) et 1 server with node.我创建了一个带有 2 个反应应用程序(客户端/管理员)和 1 个带有节点的服务器的 nx 工作区。

For each, I have created a DockerFile and at the root of the project I have my docker-compose.yml.对于每一个,我都创建了一个 DockerFile,在项目的根目录下我有我的 docker-compose.yml。

My issue: when I use the command docker-compose up --build, the 3 app runs but for the react-app, I have a blank page whereas with the command nx serve <name_app>, we can see the app.我的问题:当我使用命令 docker-compose up --build 时,3 个应用程序运行,但对于 react-app,我有一个空白页,而使用命令 nx serve <name_app>,我们可以看到该应用程序。 Here is my code:这是我的代码:

Dockerfile Dockerfile

FROM node:14-alpine

WORKDIR /home/node/app

COPY ./apps/front-client/src .

COPY ./package.json package.json

RUN npm install --production

EXPOSE 3000

USER node

CMD ["npx", "serve", "-s", ".", "-l", "3000"]

docker-compose.yml docker-compose.yml

services:
  client:
    build: 
      context: .
      dockerfile: ./apps/front-client/Dockerfile
    ports:
      - 3000:3000
    volumes:
      - ./apps/front-client/src:/app/src
...

The root div doesn't have anything inside.根 div 里面没有任何东西。 Do you know why?你知道为什么吗?

Your WORKDIR is set to /home/node/app , which means that the source is placed in /home/nome/app/src .您的WORKDIR设置为/home/node/app ,这意味着源位于/home/nome/app/src

The npx server -s. -l 3000 npx server -s. -l 3000 npx server -s. -l 3000 is executed in the /home/nome/app/src . npx server -s. -l 3000/home/nome/app/src中执行。

When you mount the volume in docker-compose, you are mounting the application on /app/src , but there is no npx serving from this folder.当您在 docker-compose 中安装卷时,您将应用程序安装在/app/src上,但此文件夹中没有npx服务。

Align both folders.对齐两个文件夹。 By an unwritten convention the proper place is /app/src so change the build file to be WORKDIR /app根据不成文的约定,正确的位置是/app/src所以将构建文件更改为WORKDIR /app

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

相关问题 如何在 Windows 容器上对接 React 应用程序 - How to dockerize React App on Windows Containers Dockerize React + Redux 应用程序运行 Node 服务器和 Webpack - Dockerize React + Redux app running Node server & Webpack 在单个容器中使用 node/express 对 VueJS 应用程序进行 Dockerize - Dockerize VueJS app with node/express in single container Dockerize 多页反应应用程序(错误:404 Not Found nginx/1.21.4) - Dockerize multipaged react app (error: 404 Not Found nginx/1.21.4) 如何将与本地mongodb对话的node.js Docker化 - How to dockerize a node.js talking to a local mongodb 在现有 Nx 项目上创建 React 应用程序时找不到模块“nx/src/config/workspaces” - Cannot find module 'nx/src/config/workspaces' on creating a React app on existing Nx project 如何将我的 angular 应用程序 dockerize 用于生产? - How can I dockerize my angular app for production? 如何使用 node --trace-warnings 运行 nx serve? - How do you run nx serve with node --trace-warnings? Dockerize react app with mongo db docker-compose 连接问题 json 错误 - Dockerize react app with mongo db docker-compose conection problem json error 如何仅将受影响的 nx 服务部署到 GCP APP Engine - How to deploy only an affected nx service to GCP APP Engine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM