推送到 heroku 容器时 - 生成大量数据

When push to heroku container - huge amount of data is generated

我正在将 React 应用程序推送到 heroku 容器。 build本身当然比较小

pl@hp:~/Desktop/proj/node/fastify-react/build$ du -h .
12K ./static/css
1,5M    ./static/js
144K    ./static/media
1,6M    ./static
1,7M

但是当我 运行 heroku container:push -a app-name web 时会生成令人难以置信的尺寸

=== Building web (/home/pl/Desktop/proj/node/fastify-react/Dockerfile)
Sending build context to Docker daemon  483.2MB
Step 1/7 : FROM node:alpine
 ---> eb56d56623e5
Step 2/7 : WORKDIR "/app"
 ---> Using cache
 ---> 38bd51aaed88
Step 3/7 : COPY ./package.json ./
 ---> Using cache
 ---> 246322cb9686
Step 4/7 : RUN npm install
 ---> Using cache
 ---> 5ef408ff8fa5
Step 5/7 : COPY . .
 ---> a82bbd411ea8
Step 6/7 : RUN npm run build
 ---> Running in a5d6474a0245

> fastify-react@0.1.0 build
> react-scripts build

Creating an optimized production build...
Compiled successfully.

File sizes after gzip:

  89.17 kB  build/static/js/main.e7da8d06.js
  593 B     build/static/css/main.03f19716.css

The project was built assuming it is hosted at /.
You can control this with the homepage field in your package.json.

The build folder is ready to be deployed.
You may serve it with a static server:

  npm install -g serve
  serve -s build

Find out more about deployment here:

  https://cra.link/deployment

Removing intermediate container a5d6474a0245
 ---> 8fa1467e608a
Step 7/7 : CMD [ "npm", "run", "start:prod" ]
 ---> Running in ee255298f781
Removing intermediate container ee255298f781
 ---> 592c31461609
Successfully built 592c31461609
Successfully tagged registry.heroku.com/xxxxxxxx/web:latest
=== Pushing web (/home/pl/Desktop/proj/node/fastify-react/Dockerfile)
Using default tag: latest
The push refers to repository [registry.heroku.com/xxxxxxx/web]
efb0d1b2452c: Pushed 
42a09a41407b: Pushing  424.2MB/424.2MB
a4e981a118e3: Pushing  342.3MB/397.3MB
1711b045f67a: Layer already exists 
ce175d7bc2d9: Layer already exists 
44811d973ddb: Layer already exists 
92dbba4d44e2: Layer already exists 
b53051d49599: Layer already exists 
8d3ac3489996: Layer already exists 
write tcp 192.168.187.221:52056->54.210.119.52:443: write: connection reset by peer
 ▸    Error: docker push exited with Error: 1

在移动设备上工作时很痛。

大家是这样还是我做错了?

谢谢

编辑:使用的 Dockerfile

FROM node:alpine

# app inside container
WORKDIR "/app"

COPY ./package.json ./

RUN npm install

COPY . .

RUN npm run build

CMD [ "npm", "run", "start:prod" ]

包的工作部分。json/scripts "start:prod": "serve -s build",

使用 .dockerignore 文件(与 Docker 文件相同的目录)从 Docker 图像中排除不必要的内容

.env
.github
node_modules

检查是否可以添加其他 folders/files(文档?)