简体   繁体   English

无法将镜像部署到 kubernetes(打包结构问题)

[英]Unable to deploy image to kubernetes (Problems with packaging structure)

On successfully building using below dockerfile, I am unable to deploy my application on eks.在使用 dockerfile 以下成功构建时,我无法在 eks 上部署我的应用程序。

 FROM node:12 # Create app directory WORKDIR /usr/src/app COPY udagram-feed/package*.json./ RUN npm ci # Bundle app source COPY. . EXPOSE 8080 CMD [ "npm", "run", "prod" ]

on fetching logs from cluster, this is what i get:从集群中获取日志,这是我得到的:

 internal/modules/cjs/loader.js:960 throw err; ^ Error: Cannot find module '/usr/src/app/www/server.js' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:957:15) at Function.Module._load (internal/modules/cjs/loader.js:840:27) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12) at internal/main/run_main_module.js:18:47 { code: 'MODULE_NOT_FOUND', requireStack: [] } npm ERR. code ELIFECYCLE npm ERR. errno 1 npm ERR: udagram-user@1.0.0 prod. `tsc && node./www/server.js` npm ERR. Exit status 1 npm ERR. npm ERR: Failed at the udagram-user@1.0.0 prod script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2020-05-20T19_11_45_220Z-debug.log

running the image locally, i have the below file structure:在本地运行图像,我有以下文件结构:

  • Dockerfile Dockerfile
  • node_modules节点模块
  • package.json package.json
  • package-lock.json封装锁.json
  • src源代码

the src/ directory contains the serves.ts sequelize.ts and other files. src/ 目录包含 serve.ts sequelize.ts 和其他文件。 Clearly there is no www/ directory.显然没有 www/ 目录。 Why is kubernetes looking for files in this directory?为什么 kubernetes 在此目录中查找文件? Any help is appreciated.任何帮助表示赞赏。 I have been stuck on this for days now, don't know what to do.这几天一直卡在这个问题上,不知道怎么办。 For file structure, please see the github repo Github有关文件结构,请参阅 github repo Github

First, your Dockerfile created a 1GB image.首先,您的 Dockerfile 创建了一个 1GB 的映像。 I modified it to create a 240MB image.我修改它以创建一个 240MB 的图像。 This Dockerfile can be further optimized;这个Dockerfile可以进一步优化; you can refer here and here for examples on creating a multi-stage Dockerfile.:您可以在此处此处参考有关创建多级 Dockerfile 的示例:

FROM node:12-alpine 
# Create app directory
WORKDIR /usr/src/app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./
RUN apk add --no-cache --virtual .gyp \
        python \
        make \
        g++ \
    && npm ci \
    && apk del .gyp
# Bundle app source
COPY . .
EXPOSE 8080
CMD [ "npm", "run", "prod" ]

Here's the docker image sizes:这是 docker 图像尺寸:

REPOSITORY                          TAG                 IMAGE ID            CREATED             SIZE
udagram-feed-alpine                 latest              185478b5eabc        11 seconds ago      247MB
udagram-feed                        latest              fbf32e67d4fa        4 minutes ago       1.07GB

Secondly, your package.json is referring to ./www/server.js file其次,您的package.json指的是./www/server.js文件

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

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