Directory to showcase how one can optimize docker image sizes with a simple React application
Find a file
hadestructhor 3869c1684f
All checks were successful
ci/woodpecker/push/workflow Pipeline was successful
feat: Dockerfile multistage
2025-01-04 17:39:34 +01:00
.woodpecker feat: Dockerfile multistage 2025-01-04 17:39:34 +01:00
public feat: Simple Dockerfile version 2025-01-04 14:29:35 +01:00
src feat: Simple Dockerfile version 2025-01-04 14:29:35 +01:00
.dockerignore feat: Dockerfile multistage 2025-01-04 17:39:34 +01:00
.gitignore feat: Simple Dockerfile version 2025-01-04 14:29:35 +01:00
Dockerfile feat: Dockerfile multistage 2025-01-04 17:39:34 +01:00
package-lock.json feat: Dockerfile multistage 2025-01-04 17:39:34 +01:00
package.json feat: Dockerfile multistage 2025-01-04 17:39:34 +01:00
README.md feat: Simple Dockerfile version 2025-01-04 14:29:35 +01:00

Pour la version en français, c'est ici: Français

English

How to reduce the size of your docker 🐳 images 💿?

We're starting from a basic React application générated with a simple Dockerfile with disastrous conséquences:

FROM node:18
COPY . .
RUN npm install
EXPOSE 3000
CMD ["npm", "start"]

For your information, the image weight a whopping 2.03GB 🤯 !!!!! A mountain 🏔️ of data for a simple web application that is empty at the moment!!!

You can test it yourself by first running the following command:

npm install

Then run the following command to build the docker image:

docker build -t 'react-simple' .

You can inspect your images and verify the size yourself with the following command:

docker image ls

I use Nushell and rigrep to filter only on the image in question using the following command:

docker image ls | from ssv | where repository starts-with 'react'

Here's the result of running this command that shows how shamefully big the image is: Size of the image

Français

Comment réduire la taille de vos images 💿 docker 🐳 ?

On part d'une application React tout juste généré et avec un Dockerfile simple mais avec de grosses conséquences :

FROM node:18
COPY . .
RUN npm install
EXPOSE 3000
CMD ["npm", "start"]

Pour indication, l'image qui en résulte pèse environ 2.03GB 🤯 !!!!! Une montagne 🏔️ de données pour une simple application web vide pour l'instant !!!

Vous pouvez le testez vous même en lançant d'abord la commande suivante:

npm install

Puis en lançant la commande suivante pour builder l'image:

docker build -t 'react-simple' .

Vous pouvez inspecter la taille de votre image avec la commande suivante:

docker image ls

J'utilise personnellement Nushell et rigrep pour ne filtrer que sur l'image en question:

docker image ls | from ssv | where repository starts-with 'react'

Voici un aperçu de ce que cette commande m'affiche avec le poids de l'image assez désastreux: Taille de cette image