📌 מעבדה זו מיועדת להדגמה מול הכיתה. לאחר ההדגמה התלמידים ייגשו למעבדה העצמאית בנפרד.


🎯 מה נכסה בהדגמה


שלב 1: יצירת האפליקציה המקומית

הסבר

נתחיל מאפליקציית Node.js פשוטה שמגיבה בפורט 3000. זו האפליקציה שנארוז ונדחוף ל-ECR.

קוד

# Create project folder
mkdir ecr-demo && cd ecr-demo
// app.js
const http = require('http');
const PORT = process.env.PORT || 3000;

const server = http.createServer((req, res) => {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('Hello from ECR!\n');
});

server.listen(PORT, () => {
  console.log(`Server running on port ${PORT}`);
});
{
  "name": "ecr-demo",
  "version": "1.0.0",
  "main": "app.js",
  "scripts": { "start": "node app.js" }
}
# Dockerfile
FROM node:18-alpine
WORKDIR /app
COPY package.json .
COPY app.js .
RUN npm install --omit=dev
EXPOSE 3000
CMD ["node", "app.js"]

בניית ה-Image

⚠️ אם אתה על Mac עם Apple Silicon — חייב לציין --platform linux/amd64 כדי שה-Image ירוץ על EC2

# Build the image for linux/amd64 (required when building on Apple Silicon)
docker buildx build --platform linux/amd64 -t ecr-demo:latest .