我刚开始使用Docker,我正在尝试让一个简单的React应用程序在Docker中工作。
这是我的文件组织
/project-files
Dockerfile
../clientInside client是一个基本的React应用程序,这是我的Dockerfile
FROM node:13.8.0-stretch
WORKDIR /client
COPY /client/package.json ./client/package.json
RUN npm install
COPY /client /client
EXPOSE 8080
CMD ["npm", "start"]我从运行以下命令:
docker build -t test .\project-files\而且它似乎构建正确。然后我跑
docker run -p 8080:8080 test而且它似乎可以正确编译。我得到了在React应用程序中看到的所有消息和警告
> client@0.1.0 start /client
> react-scripts start
ℹ 「wds」: Project is running at http://172.17.0.2/
ℹ 「wds」: webpack output is served from
ℹ 「wds」: Content not from webpack is served from /client/public
ℹ 「wds」: 404s will fallback to /
Starting the development server...
Compiled with warnings.
./src/scenes/Home.js
Line 5:29: 'Card' is defined but never used no-unused-vars
Search for the keywords to learn more about each warning.
To ignore, add // eslint-disable-next-line to the line before.但是当我转到http://localhost:8080/时,我得到一个“这个页面不工作,本地主机没有发送任何数据。”
发布于 2020-03-01 06:00:38
我刚刚复制了Dockerfile的内容,并设法让它运行(使用create-react-app):
FROM node:13.8.0-stretch
WORKDIR /client
COPY ./client/package.json /client/package.json
RUN npm install
COPY ./client /client
EXPOSE 3000
CMD ["npm", "start"]我做了以下更改:
8080更改为3000docker run -p 3000:3000 test中使用3000与Dockerfile
docker build -t test .当我访问http://localhost:3000/时,它显示了我的应用程序。
总而言之,我认为是复制路径和EXPOSEd端口造成的
我的文件结构:
.
├── _Dockerfile
├── _client
| ├── package.json
| ├── package-lock.json
| ├── public
| └── srchttps://stackoverflow.com/questions/60469757
复制相似问题