docker run
पैकेज और रनटाइम
इस्तेमाल
docker run [-d] [-p <host>:<container>] <image> [command]हर बार image से एक नया container बनाकर चलाता है, इसलिए दो बार चलाने पर दो container बन जाते हैं और रुके हुए को फिर चलाना docker start है; -p के बिना host से कुछ नहीं पहुँचता, और -v के बिना जो लिखा जाता है container के साथ मिट जाता है।
आम विकल्प
| विकल्प | अर्थ |
|---|---|
| -d | run in the background and print the id |
| -p 8080:80 | publish a container port on the host |
| -it | interactive with a terminal, for a shell |
| --rm | delete the container when it exits |
| -v <host>:<path> | mount a host folder or named volume |
| -e KEY=value | set an environment variable |
| --name <name> | give it a name instead of a random one |
| --network <net> | attach it to a network |
उदाहरण
docker run --rm -it ubuntu basha throwaway shell in a container
docker run -d -p 8080:80 --name web nginxnginx in the background, reachable on localhost:8080
docker run --rm -v "$PWD":/app -w /app node:22 npm testruns your tests in a container without installing node
सवाल हमेशा यही है कि क्या कहाँ जाए: इस प्रोजेक्ट के भीतर, या पूरी मशीन पर।
कैसे पढ़ें
- बड़े कोष्ठक [ ] उस हिस्से को दिखाते हैं जिसे छोड़ा जा सकता है।
- तीन बिंदु … का मतलब है एक से ज़्यादा दिए जा सकते हैं।
- विकल्पों में बड़े-छोटे अक्षर मायने रखते हैं — कुछ कमांड में -r और -R अलग काम करते हैं।
आम सवाल
Q. docker run क्या करता है?
हर बार image से एक नया container बनाकर चलाता है, इसलिए दो बार चलाने पर दो container बन जाते हैं और रुके हुए को फिर चलाना docker start है; -p के बिना host से कुछ नहीं पहुँचता, और -v के बिना जो लिखा जाता है container के साथ मिट जाता है।
Q. इसे कैसे लिखें?
docker run [-d] [-p <host>:<container>] <image> [command] — बड़े कोष्ठक वह हिस्सा दिखाते हैं जो छोड़ा जा सकता है।
Q. कितने विकल्प जानने लायक़ हैं?
यहाँ 8 दिए हैं; पूरी सूची man docker में है। यह कमांड पैकेज और रनटाइम में आती है।
मिलती-जुलती कमांड
man पेज: man docker-run