अपने Docker इमेज के लिए स्टार्ट कमांड चुनना

Docker परिचय

Tim Sangster

Software Engineer @ DataCamp

स्टार्ट कमांड क्या है?

hello-world इमेज टेक्स्ट प्रिंट करती है और रुक जाती है.

docker run hello-world
Hello from Docker!

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon created a new container from the hello-world image which runs the
    executable that produces the output you are currently reading.
 3. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.
Docker परिचय

स्टार्ट कमांड क्या है?

python वाली इमेज स्टार्टअप पर python चला सकती है.

docker run python3-sandbox
Python 3.10.6 (main, Nov  2 2022, 18:53:38) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
...
....
>>> exit()
repl@host:/#
Docker परिचय

स्टार्टअप पर शेल कमांड चलाना

CMD <shell-command>

CMD निर्देश:

  • इमेज शुरू होते ही चलता है.
  • इमेज का साइज नहीं बढ़ाता.
  • बिल्ड समय नहीं बढ़ाता.
  • कई होने पर, केवल आखिरी असर करता है.
Docker परिचय

आम उपयोग

ऐप्लिकेशन शुरू करना जो वर्कफ़्लो चलाए या बाहरी कनेक्शन स्वीकार करे.

CMD python3 my_pipeline.py
CMD postgres

ऐसा स्क्रिप्ट शुरू करना जो आगे कई ऐप्लिकेशन शुरू करे

CMD start.sh
CMD python3 start_pipeline.py
Docker परिचय

यह कब रुकेगी?

$$

  • hello-world इमेज -> टेक्स्ट प्रिंट करने के बाद
  • डेटाबेस इमेज -> जब डेटाबेस बंद हो

$$

ज्यादा सामान्य इमेज को ज्यादा सामान्य स्टार्ट कमांड चाहिए.

  • Ubuntu इमेज -> जब शेल बंद हो
Docker परिचय

डिफॉल्ट स्टार्ट कमांड ओवरराइड करना

इमेज शुरू करना

docker run <image>

कस्टम स्टार्ट कमांड के साथ इमेज शुरू करना

docker run <image> <shell-command>

कस्टम स्टार्ट कमांड के साथ इंटरैक्टिव मोड में इमेज शुरू करना

docker run -it <image> <shell-command>
docker run -it ubuntu bash
Docker परिचय

सारांश

उपयोग Dockerfile निर्देश
कंटेनर इमेज से शुरू हो तो चलने वाला शेल कमांड जोड़ें. CMD <shell-command>

उपयोग शेल कमांड
इमेज में सेट CMD को ओवरराइड करें docker run <image> <shell-command>
इमेज में सेट CMD को ओवरराइड करें और इंटरैक्टिव चलाएँ docker run -it <image> <shell-command>
Docker परिचय

अभ्यास करते हैं!

Docker परिचय

Preparing Video For Download...