docker build
पैकेज और रनटाइम
इस्तेमाल
docker build -t <name>:<tag> [-f <Dockerfile>] <context>Dockerfile से image बनाता है; अंत का बिंदु वह build context है जो daemon को भेजा जाता है, इसलिए भारी फ़ोल्डर build धीमा कर देता है (.dockerignore से छाँटें), और COPY उसी context के भीतर की फ़ाइलें ही देख पाता है।
आम विकल्प
| विकल्प | अर्थ |
|---|---|
| -t <name>:<tag> | name the image; without it you only get an id |
| -f <file> | use a Dockerfile that is not ./Dockerfile |
| --no-cache | rebuild every layer |
| --build-arg KEY=value | pass an ARG into the build |
| --target <stage> | stop at one stage of a multi-stage file |
| --platform linux/amd64 | build for another architecture |
| --progress=plain | full log output instead of the collapsed view |
उदाहरण
docker build -t myapp:1.0 .builds from ./Dockerfile with the current folder as context
docker build -f docker/Dockerfile.dev -t myapp:dev .another Dockerfile, same context
docker build --platform linux/amd64 -t myapp:1.0 .an x86 image built on an Apple Silicon Mac
सवाल हमेशा यही है कि क्या कहाँ जाए: इस प्रोजेक्ट के भीतर, या पूरी मशीन पर।
कैसे पढ़ें
- बड़े कोष्ठक [ ] उस हिस्से को दिखाते हैं जिसे छोड़ा जा सकता है।
- तीन बिंदु … का मतलब है एक से ज़्यादा दिए जा सकते हैं।
- विकल्पों में बड़े-छोटे अक्षर मायने रखते हैं — कुछ कमांड में -r और -R अलग काम करते हैं।
आम सवाल
Q. docker build क्या करता है?
Dockerfile से image बनाता है; अंत का बिंदु वह build context है जो daemon को भेजा जाता है, इसलिए भारी फ़ोल्डर build धीमा कर देता है (.dockerignore से छाँटें), और COPY उसी context के भीतर की फ़ाइलें ही देख पाता है।
Q. इसे कैसे लिखें?
docker build -t <name>:<tag> [-f <Dockerfile>] <context> — बड़े कोष्ठक वह हिस्सा दिखाते हैं जो छोड़ा जा सकता है।
Q. कितने विकल्प जानने लायक़ हैं?
यहाँ 7 दिए हैं; पूरी सूची man docker में है। यह कमांड पैकेज और रनटाइम में आती है।
मिलती-जुलती कमांड
man पेज: man docker-build