
Docker done better
Chapter 1: What I did I have been building my own project for 3-4 weeks now, and I just realized something after I launched my website. The tech stack is built on Next.js, Node.js, Strapi, OpenAI, MongoDB, etc., and I am using Docker to containerize it. Initially, I didn't pay much attention as I wanted to launch it ASAP, but now, when I am focusing on the storage consumption of the Docker images, then its off the charts. My Next.JS Docker image is of size 3.01 GB Yes, it's hilarious. Because I am doing it the wrong way. The real culprit (it's me, I guess ): My initial Dockerfile of Next.js looks like this # Use official Node image FROM node:22 # Create app directory WORKDIR /app # Copy package files first COPY package*.json ./ # Install dependencies RUN npm install # Copy the rest of the project COPY . . # Build the Next.js app RUN npm run build # Expose port EXPOSE 3000 # Start the app CMD ["npm", "start"] You can clearly see the issue here: The default node:22 image is Debian-based
Continue reading on Dev.to Webdev
Opens in a new tab



