hudy9x/namviek

Docker image size too big (2Gb)

Closed this issue · 2 comments

The docker image is too big > 2GB for now. It's hard to push to some free registry like docker hub
Need to optimize the docker image to < 1GB
Try to separate backend and frontend into 2 image
Regarding the backend, only install packages in production mode
And the frontend, try to use 'standalone' config in next.config.js to export necessary package and files into one folder

For frontend image

  • use node:lts-alpine for small size
  • add `output: 'standalone'
    const nextConfig = {
    output: 'standalone',
    // ...
    }
  • stop using base stage after generating prisma schema and building project

=> Result: 2.2Gb -> 479mb

Let's try to optimize it less than 400mb

fixed it by separating backend and frontend into 2 containers
now each has <500 mb
checkout refactor/optimize-docker-image