[英]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.