The Secrets to Slash Docker Image Size by 10x

Before Optimization A typical Dockerfile for a Node.js application looks like this: 1 2 3 4 5 FROM node:18 WORKDIR /app COPY . . RUN npm install CMD ["npm", "start"] This image ends up being over 1GB in size. The main reasons for this are: Heavy base image Development tools included Presence of unnecessary files Accumulation of cache files Optimization Techniques 1. Implement Multi-Stage Builds Separate the build and runtime stages. ...

February 17, 2025 · 3 min · 555 words · In-Jun Hwang

Crafting a Dockerfile for your React Application

The Need for a Dockerfile Deploying your React applications as Docker containers offers the following advantages: Maintaining consistency between development and production environments Standardizing the build, test, and deployment process Enhancing scalability and flexibility Ease of environment variable management Basic Dockerfile Structure In its simplest form, a Dockerfile can be as follows: 1 2 3 4 5 6 7 8 FROM node:18 WORKDIR /app COPY package*.json ./ RUN npm install COPY . . RUN npm run build EXPOSE 3000 CMD ["npm", "start"] While this approach works, it is far from optimized, resulting in larger image sizes and longer build times. ...

February 17, 2025 · 2 min · 426 words · In-Jun Hwang

Understanding Docker Image Layers

Concept and Structure of Layers A Docker image is composed of multiple read-only layers. Each layer stores the filesystem changes introduced by a command in the Dockerfile. This is similar to commits in Git. It improves efficiency by storing only the changes. Docker mounts the layers as a single filesystem using a union file system. A writable container layer is added on top of the last layer. This can be visualized as multiple transparent sheets stacked on top of each other. ...

February 17, 2025 · 3 min · 531 words · In-Jun Hwang