PqgpNgA0wk
V2EX  ›  Docker

关于 Dockerfile 使用了 alpine 镜像打包后的镜像依然很大的疑问

  •  
  •   PqgpNgA0wk · Jan 23, 2024 · 1828 views
    This topic created in 857 days ago, the information mentioned may be changed or developed.

    目前在打包一个 nuxt3 项目,Dockerfile 内容如下

    FROM node:20-alpine AS build
    
    WORKDIR /app
    
    COPY . .
    
    RUN npm install && npm run build
    
    FROM node:20-alpine AS release
    
    WORKDIR /dist
    
    COPY --from=build /app/.output/* .
    
    EXPOSE 3000
    
    CMD node server/index.mjs
    

    生成的镜像有 147MB ,按照我搜到的教程,我的理解应该只有 70 多兆才对

    然后我用 docker history 查看了构建层

    高亮这条就已经有 121MB 了,可我在 dockerhub 上看的 node:20-alpine 镜像的同一层只有 42.17MB

    不解为什么本地打包时候这一层会变大🤔

    4 replies    2024-01-24 18:02:16 +08:00
    ss098
        1
    ss098  
       Jan 23, 2024
    Docker Hub 上显示的是压缩后的 layer 大小
    PqgpNgA0wk
        2
    PqgpNgA0wk  
    OP
       Jan 24, 2024
    @ss098 了解了解
    julyclyde
        3
    julyclyde  
       Jan 24, 2024
    你高亮的那一行,没在你自己的 Dockerfile 里啊
    这是 node:20-alpine 的内容吧?

    这样的话,你应该拿最终结果和 FROM 做比较,看增加了多少;而不是直接看最终大小吧?
    只要没有过份增加,那你做的就没啥错;至于为什么底层那么大,那也不是你能管得了的事了吧
    PqgpNgA0wk
        4
    PqgpNgA0wk  
    OP
       Jan 24, 2024
    @julyclyde 好的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2634 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 10:29 · PVG 18:29 · LAX 03:29 · JFK 06:29
    ♥ Do have faith in what you're doing.