חלק 1: יצירת אפליקציית Express בסיסית

פעולות

  1. צרו תיקייה חדשה ואתחלו פרויקט Node.js (npm init -y)

  2. התקינו express:

     npm i express
    
  3. צרו src/index.js עם שרת Express פשוט שמאזין על פורט 3000

const express = require('express');

const app = express();

const PORT = 3000;

app.get('/', (req, res) => {
  res.send('Hello from Express!');
});

app.listen(PORT, () => {
  console.log(`Server is running on port ${PORT}`);
});
  1. הוסיפו start script ל-package.json
{
  "name": "simple-express-app",
  "version": "1.0.0",
  "description": "Simple Express application",
  "main": "app.js",
  "scripts": {
    "start": "node index.js"
  },
  "dependencies": {
    "express": "^4.9.2"
  }
}
  1. בדקו שהאפליקציה עולה מקומית
npm run start

חלק 2: יצירת Dockerfile והרצה ראשונה

פעולות

  1. צרו Dockerfile עם node:22-alpine כ-base image
  2. הוסיפו .dockerignore שמתעלם node_modules
  3. בנו את ה-image, הריצו container ובדקו שהאפליקציה עולה

חלק 3: הוספת ENV ל-Dockerfile

הסבר

instruction ENV מגדיר משתנה סביבה בתוך ה-image. הקוד יכול לקרוא אותו בזמן ריצה.