Ravindra BagaleCourses & study guides Track your progress

Guides

तुमचा पहिला Dockerfile लिहा (नवशिक्यांसाठी)

Read this guide in: English · मराठी · हिंदी

Why Dockerfile हवा आहे? कारण developers आणि operations मध्ये खरा problem आहे. Developers कडे index.html (किंवा app) laptop वर ठीक दिसतो. Operations — server side वरील employee — विचारतो EC2 वर तोच कसा चालवायचा. Files copy पुरेसे नाही; server ला runtime bits ही हवेत. Dockerfile shared recipe आहे: docker build → image, docker run → container.

मित्रांनो, एक file कशी चालणारी site होते ते पहा. नावे नंतर येतील — आधी fight समजा.

थोडक्यात उत्तर

हे पाच पॉइंट्स लक्षात ठेवा:

  1. Developer — app files own करतो.
  2. Operations — server-side person ज्याला EC2 वर तोच site चालवायचा आहे.
  3. Problem — recipe नसलेली file copy; हाताने packages; पुढच्या आठवड्यात drift.
  4. Dockerfile — FROM → COPY → EXPOSE → CMD; मग build आणि run.
  5. लक्षात ठेवा: file → Dockerfile → image → container.

Language: English · मराठी · हिंदी

Problem? Suppose we are…

Suppose we are building Instagram (like updates)

Tiny status page mobile app शी जुळायला हवे. Developer HTML email करतो. Operations EC2 वर हाताने nginx. पुढच्या आठवड्यात steps विसरतात.

Suppose we are working at Netflix and we are giving updates

प्रत्येक microservice known image tag म्हणून ship व्हायला हवे. Dockerfile नसेल तर “laptop build” production नाही.

Suppose you are working in Infosys on a client project

Client operations म्हणतो: “Dockerfile आणि tag द्या — files ची zip स्वीकारणार नाही.” तो shared contract.

आधी Docker हवा (install on EC2).

Dockerfile builds an image; docker run starts a container A Dockerfile lists FROM, COPY, RUN and CMD. docker build creates a read-only image. docker run starts a container from that image. Dockerfile FROM nginx:alpine COPY index.html … EXPOSE 80 CMD ["nginx",…] build Image docker build -t myweb:1 read-only package layers (cacheable) myweb:1 run Container docker run -p 8080:80 running copy of image same bits on laptop & server --name myweb Dockerfile → image → run Contract for Infosys-style client ops: give a Dockerfile + tag, not a mystery zip

Dockerfile instructions → docker build creates a read-only image → docker run starts a container.

Dockerfile to docker build Terminal-style teaching diagram: Dockerfile lines, docker build -t myweb:1, then docker images.

Terminal-style teaching diagram: Dockerfile lines, docker build -t myweb:1, then docker images.

Dockerfile कसे उत्तर देते

mkdir myweb && cd myweb
cat > index.html <<'EOF'
<!doctype html>
<html><body><h1>DevOps lab page</h1><p>Same bits on laptop and server</p></body></html>
EOF
cat > Dockerfile <<'EOF'
FROM nginx:alpine
COPY index.html /usr/share/nginx/html/index.html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
EOF
docker build -t myweb:1 .
docker run --rm -d -p 8080:80 --name myweb myweb:1
curl -s http://localhost:8080 | head

HTML बदलले? नवीन tag: docker build -t myweb:2 .

Ravindra Bagale's Tip

Files बदलून जुने container पुन्हा चालवणे = जुनी zip copy. Edit → build → नवीन tag. लक्षात ठेवा.

Common errors

Pain Fix
Dockerfile सापडत नाही योग्य folder मध्ये cd
COPY failed Files Dockerfile शेजारी
Page update होत नाही Rebuild + नवीन tag
Port busy -p 8081:80
Huge context .dockerignore

समजलं का? Why Dockerfile = developer आणि server-side यांची shared recipe; Instagram / Netflix / Infosys “suppose”; प्रत्येक build tag करा. आज myweb:1.

Frequently asked questions

What is a Dockerfile?

A text file of instructions that docker build follows to create an image.

What is FROM?

FROM sets the base image you start from, for example a small Linux or language runtime.

COPY vs ADD?

Prefer COPY for local files. ADD has extra magic most beginners do not need.

Why does build context matter?

docker build sends the folder (.) to the daemon. Keep the context small and use .dockerignore.

What does EXPOSE do?

It documents a port. You still map ports with -p when you run.

CMD vs ENTRYPOINT?

CMD is the default command; ENTRYPOINT is harder to override. Beginners usually start with CMD.