← Back to Node.js Course | Chapter 10: Deployment & Best Practices | Lesson 4 of 7

Node के लिए Docker के Basics

एक Docker image आपकी app और इसकी dependencies package करता है ताकि यह हर जगह same चले।
Syntax
javascript
FROM node:version
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
CMD ["node", "app.js"]

Node के लिए Docker Basics

एक Dockerfile एक Node base image से शुरू होती है, package files copy करती है, npm ci चलाती है, source copy करती है, और start command set करती है। पहले package.json copy करना Docker को dependency layer cache करने देता है।

node_modules और secrets के लिए एक .dockerignore इस्तेमाल करें और एक non-root user की तरह चलाएँ।

Note: Images छोटी रखने के लिए एक slim या alpine base image और एक multi-stage build इस्तेमाल करें।

उदाहरण: Docker basics for Node

bash
# Dockerfile
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
USER node
EXPOSE 3000
CMD ["node", "server.js"]

⚠️ Run this in your own terminal or Node.js environment.

Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. node_modules को image में copy करना
  2. root की तरह चलाना
  3. production में dev dependencies install करना
चैप्टर सारांश
  • Dockerfile image describe करती है
  • Caching के लिए पहले package files copy करें
  • .dockerignore इस्तेमाल करें
  • Non-root की तरह चलाएँ
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.