{"id":1535,"date":"2021-04-10T09:57:35","date_gmt":"2021-04-10T09:57:35","guid":{"rendered":"https:\/\/www.ipcpu.com\/?p=1535"},"modified":"2021-09-10T09:58:06","modified_gmt":"2021-09-10T09:58:06","slug":"nodejs-docker-npm-install","status":"publish","type":"post","link":"https:\/\/c.ipcpu.com\/2021\/04\/nodejs-docker-npm-install\/","title":{"rendered":"nodejs\u5728docker\u73af\u5883\u8fdb\u884cnpm install\u7684\u7f13\u5b58\u95ee\u9898"},"content":{"rendered":"

nodejs\u5728docker\u73af\u5883\u7684\u7f13\u5b58\u95ee\u9898.md<\/p>\n

\u4e00\u3001\u9047\u5230\u7684\u95ee\u9898<\/h2>\n

\u539f\u5148\u6211\u4eec\u7684nodejs\u8fd0\u884c\u5728\u865a\u62df\u673a\u73af\u5883\u4e0b\uff0cCICD\u4e5f\u662f\u5728\u865a\u62df\u673a\u73af\u5883\u4e0b\uff0c\u73b0\u5728\u8fdb\u884c\u5bb9\u5668\u5316\u6539\u9020\uff0c\u53d1\u73b0\u6211\u4eec\u7684npm install \u6267\u884c\u65f6\u95f4\u592a\u957f\u4e86\uff0c\u4e00\u4e2a\u5f88\u5c0f\u7684\u9879\u76ee\uff0c\u539f\u672c\u51e0\u5206\u949f\u5c31\u5b8c\u6210\u7684\u4efb\u52a1\uff0c\u5728gitlab dind\u73af\u5883\u4e0b\uff0c\u9700\u8981\u4e09\u56db\u5341\u5206\u949f\uff0c\u5b9e\u5728\u662f\u592a\u6162\u4e86\u3002<\/p>\n

\u4e8c\u3001\u7f13\u5b58\u8c03\u7814<\/h2>\n

\u7ecf\u8fc7\u67e5\u627e\u76f8\u5173\u8d44\u6599\uff0c\u6211\u4eec\u53d1\u73b0\uff0cnpm\u5728\u672c\u5730\u73af\u5883\u7559\u6709\u7f13\u5b58\uff0c\u5982\u679c\u5339\u914d\u4e0a\u7f13\u5b58\uff0c\u4f18\u5148\u4f7f\u7528\u7f13\u5b58\u3002
\n\u7f13\u5b58\u76ee\u5f55\u4f4d\u7f6e\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u67e5\u8be2 <\/p>\n

\n
npm config get cache<\/code><\/pre>\n<\/div>\n

<\/p>\n

\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u7f13\u5b58\uff0c\u6211\u4eec\u4f18\u5148\u60f3\u5230\u7684\u662f\u5c06gitlab\u4e3b\u673a\u7f13\u5b58\u76ee\u5f55\u6620\u5c04\u5230docker\u5bb9\u5668\uff0c\u8fd9\u6837\u591a\u8fd0\u884c\u51e0\u6b21node\u9879\u76ee\uff0cgitlab\u4e3b\u673a\u7f13\u5b58\u76ee\u5f55\u5c31\u4f1a\u88ab\u586b\u6ee1\u3002
\n\u4f46\u662f\u6211\u4eec\u4f7f\u7528\u7684\u662fgitlab DinD\u73af\u5883\uff0c\u76f4\u63a5\u6620\u5c04\u672c\u5730\u76ee\u5f55\u662f\u884c\u4e0d\u901a\u7684\uff0c\u56e0\u6b64\u6211\u4eec\u9009\u62e9\u5c06\u7f13\u5b58\u76ee\u5f55\u76f4\u63a5\u6253\u5230\u955c\u50cf\u91cc\uff0c \u7f16\u8bd1\u65f6\u95f4\u63a7\u5236\u5728\u4e8610\u5206\u949f\u4ee5\u5185\u3002<\/p>\n

\n
# build stage\nFROM reg.ipcpu.com\/jenkins\/node:10.16.0-withcache as build-stage\nWORKDIR \/app\nCOPY package*.json \/app\nRUN npm install\nCOPY \/ \/app\nRUN cp  .env.production  \/app\/.env\nRUN npm run build:prod\n\n# production stage\nFROM nginx:stable-alpine as production-stage\nCOPY --from=build-stage \/app\/dist \/usr\/share\/nginx\/html\nEXPOSE 80\nCMD [\"nginx\", \"-g\", \"daemon off;\"]\n<\/code><\/pre>\n<\/div>\n

\u4e09\u3001\u7f13\u5b58\u955c\u50cf\u5982\u4f55\u7ef4\u62a4\uff1f<\/h2>\n

\u76ee\u524d\u60f3\u5230\u7684\u529e\u6cd5\uff0c\u5b9a\u671f\u83b7\u53d6gitlab\u91ccCICD\u6d3b\u8dc3top10 \u9879\u76ee\uff0c
\n\u5728\u7a7a\u767d\u865a\u673a\u73af\u5883\u8fdb\u884cnpm install \uff0c\u7136\u540e\u6253\u5305\u7f13\u5b58\u76ee\u5f55\uff0c\u5408\u5e76\u5230docker\u955c\u50cf\u3002
\n\u4e3a\u4ec0\u4e48\u4e0d\u76f4\u63a5\u7528docker\uff0cnpm install \u5f88\u591a\u65f6\u5019\u8fde\u63a5github\u7b49\u7f51\u7edc\u5bb9\u6613\u4e2d\u65ad\uff0c\u5728\u865a\u62df\u673a\u73af\u5883\u4e0b\u66f4\u5bb9\u5668\u5904\u7406\u8fd9\u6837\u7684\u5f02\u5e38\u60c5\u51b5\uff0c\u6b64\u65f6\u4f7f\u7528docker \u53cd\u800c\u4f1a\u589e\u52a0\u4eba\u5de5\u8c03\u8bd5\u6210\u672c\u3002<\/p>\n

\u56db\u3001DinD\u6539\u6210DooD\uff1f<\/h2>\n

\u786e\u5b9e\u6709\u7740\u60f3\u6cd5\uff0c\u76ee\u524d\u6765\u770b\uff0c\u4ee5\u6548\u7387\u4f18\u5148\u7684\u539f\u5219\uff0c\u6211\u4eec\u540e\u7eed\u53ef\u80fd\u4f1a\u9009\u62e9DooD\u3002<\/p>\n

\u8f6c\u8f7d\u8bf7\u6ce8\u660e\uff1aIPCPU-\u7f51\u7edc\u4e4b\u8def<\/a> » nodejs\u5728docker\u73af\u5883\u8fdb\u884cnpm install\u7684\u7f13\u5b58\u95ee\u9898<\/a><\/p>","protected":false},"excerpt":{"rendered":"

nodejs\u5728docker\u73af\u5883\u7684\u7f13\u5b58\u95ee\u9898.md \u4e00\u3001\u9047\u5230\u7684\u95ee\u9898 \u539f\u5148\u6211\u4eec\u7684nodejs\u8fd0\u884c\u5728\u865a\u62df\u673a\u73af\u5883\u4e0b\uff0cCICD\u4e5f\u662f\u5728\u865a\u62df\u673a\u73af\u5883\u4e0b\uff0c\u73b0\u5728\u8fdb\u884c\u5bb9\u5668\u5316\u6539\u9020\uff0c\u53d1\u73b0\u6211\u4eec\u7684npm install \u6267\u884c\u65f6\u95f4\u592a\u957f\u4e86\uff0c\u4e00\u4e2a\u5f88\u5c0f\u7684\u9879\u76ee\uff0c\u539f\u672c\u51e0\u5206\u949f\u5c31\u5b8c\u6210\u7684\u4efb\u52a1\uff0c\u5728gitlab dind\u73af\u5883\u4e0b\uff0c\u9700\u8981\u4e09\u56db\u5341\u5206\u949f\uff0c\u5b9e\u5728\u662f\u592a\u6162\u4e86\u3002 \u4e8c\u3001\u7f13\u5b58\u8c03\u7814 \u7ecf\u8fc7\u67e5\u627e\u76f8\u5173\u8d44\u6599\uff0c\u6211\u4eec\u53d1\u73b0\uff0cnpm\u5728\u672c\u5730\u73af\u5883\u7559\u6709\u7f13\u5b58\uff0c\u5982\u679c\u5339\u914d\u4e0a\u7f13\u5b58\uff0c\u4f18\u5148\u4f7f\u7528\u7f13\u5b58\u3002 \u7f13\u5b58\u76ee\u5f55\u4f4d\u7f6e\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u67e5\u8be2 npm config get cache \u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u7f13\u5b58\uff0c\u6211\u4eec\u4f18\u5148\u60f3\u5230\u7684\u662f\u5c06gitlab\u4e3b\u673a\u7f13\u5b58\u76ee\u5f55\u6620\u5c04\u5230docker\u5bb9\u5668\uff0c\u8fd9\u6837\u591a\u8fd0\u884c\u51e0\u6b21node\u9879\u76ee\uff0cgitlab\u4e3b\u673a\u7f13\u5b58\u76ee\u5f55\u5c31\u4f1a\u88ab\u586b\u6ee1\u3002 \u4f46\u662f\u6211\u4eec\u4f7f\u7528\u7684\u662fgitlab DinD\u73af\u5883\uff0c\u76f4\u63a5\u6620\u5c04\u672c\u5730\u76ee\u5f55\u662f\u884c\u4e0d\u901a\u7684\uff0c\u56e0\u6b64\u6211\u4eec\u9009\u62e9\u5c06\u7f13\u5b58\u76ee\u5f55\u76f4\u63a5\u6253\u5230\u955c\u50cf\u91cc\uff0c \u7f16\u8bd1\u65f6\u95f4\u63a7\u5236\u5728\u4e8610\u5206\u949f\u4ee5\u5185\u3002 # build stage FROM reg.ipcpu.com\/jenkins\/node:10.16.0-withcache as build-stage WORKDIR \/app COPY package*.json \/app RUN npm install COPY \/ \/app RUN cp .env.production \/app\/.env RUN npm run build:prod # production stage FROM nginx:stable-alpine as production-stage COPY –from=build-stage \/app\/dist \/usr\/share\/nginx\/html EXPOSE […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[68,222],"_links":{"self":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts\/1535"}],"collection":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/comments?post=1535"}],"version-history":[{"count":1,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts\/1535\/revisions"}],"predecessor-version":[{"id":1536,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts\/1535\/revisions\/1536"}],"wp:attachment":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/media?parent=1535"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/categories?post=1535"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/tags?post=1535"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}