简体   繁体   English

如何在 Windows 容器上对接 React 应用程序

[英]How to dockerize React App on Windows Containers

I have a React app that I would like to Dockerize for Windows containers.我有一个 React 应用程序,我想为 Windows 容器 Dockerize。 this my Dockerfile:这是我的 Dockerfile:

FROM stefanscherer/node-windows

# Override the base log level (info).
ENV NPM_CONFIG_LOGLEVEL warn

# Expose port for service
EXPOSE 80

# Install and configure `serve`.
RUN npm install -g serve

# Copy source code to image
COPY . .

# Install dependencies
RUN npm install

# Build app and start server from script
CMD [ "npm", "start" ]

The image is successfully built, but when I try to run it I get this error:图像已成功构建,但是当我尝试运行它时出现此错误:

Error response from daemon: container 3b4b9e2bab346bbd95b9dc144429026c1abbe7f4d088f1f10d4c959364f50e9e encountered an error during CreateProcess: failure in a Windows system call: The system cannot find the file specified. (0x2) extra info: {"CommandLine":"npm start","WorkingDirectory":"C:\\","Environment":{"NPM_CONFIG_LOGLEVEL":"warn"},"CreateStdInPipe":true,"CreateStdOutPipe":true,"CreateStdErrPipe":true,"ConsoleSize":[0,0]}.

I am new with Docker so I not sure if I am missing something.我是 Docker 的新手,所以我不确定我是否遗漏了什么。 Any ideas?有任何想法吗?

This error probabily is because the image base is nanoserver in this case, and then the react-scripts don't works well.这个错误可能是因为在这种情况下图像库是nanoserver ,然后react-scripts不能正常工作。 Also the docker images from stefanscherer/node-windows arn't updates (the latest versions of NodeJs in these images are 12.x).此外,来自stefanscherer/node-windows的 docker 图像也没有更新(这些图像中 NodeJ 的最新版本是 12.x)。

Because this, I made one new docker image with some LTS versions as 14.19.0, 16.17.0 for example.因此,我制作了一张新的 docker 映像,其中一些 LTS 版本为 14.19.0、16.17.0。

The docker image ishenriqueholtz/node-win , where the tags are the NodeJs versions. docker 镜像是henriqueholtz/node-win ,其中标签是 NodeJs 版本。

Note : For now, the NodeJs don't have official image to windows container.注意:目前,NodeJs 没有 windows 容器的官方镜像。

In the README in docker hub, you can see one example and the links to some articles with more examples.在 docker 集线器中的自述文件中,您可以看到一个示例以及一些包含更多示例的文章的链接。

See some articles with examples:请参阅一些带有示例的文章:

Below one example to run your create-react-app , for example (obviously, you must change the volume to your folder - use powershell):下面是一个运行您的create-react-app的示例,例如(显然,您必须将卷更改为您的文件夹 - 使用 powershell):

docker run -t -p 3000:3000 --name=my-own-cra-windows-container -v C:\Projects\my-own-cra\:C:\app\ henriqueholtz/node-win:16.17.0 cmd /c "npm -v & node -v & npm start"

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM