我正在將 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" ]
package.json/scripts 的作業部分
"start:prod": "serve -s build",
uj5u.com熱心網友回復:
使用.dockerignore檔案(與 Dockerfile 相同的目錄)從 Docker 映像中排除不必要的內容
.env
.github
node_modules
檢查您是否可以添加其他檔案夾/檔案(檔案?)
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/451217.html
