Docker परिचय
Tim Sangster
Software Engineer @ DataCamp
Docker निर्देशों से फ़ाइल डाउनलोड और अनज़िप करना.
RUN curl http://example.com/example_folder.zip
RUN unzip example_folder.zip
फ़ाइल सिस्टम बदलेगा और ये जुड़ेंगे:
/example_folder.zip
/example_folder/
example_file1
example_file2
इन्हीं बदलावों को इमेज में स्टोर किया जाता है.
Dockerfile की हर निर्देश इमेज फ़ाइल सिस्टम में हुए अपने बदलावों से जुड़ी होती है.
FROM docker.io/library/ubuntu
=> हमें Ubuntu चलाने के लिए ज़रूरी सभी फ़ाइलों के साथ एक शुरुआती फ़ाइल सिस्टम मिलता है
COPY /pipeline/ /pipeline/
=> /pipeline/ फ़ोल्डर बनता है
=> कई फ़ाइलें /pipeline/ फ़ोल्डर में कॉपी होती हैं
RUN apt-get install -y python3
=> /var/lib/ में python3 जुड़ता है
--> Docker image: Dockerfile की सभी निर्देशों से फ़ाइल सिस्टम में हुए सभी बदलाव.
Dockerfile बनाते समय Docker बताता है कि वह किस layer पर काम कर रहा है:
=> [1/3] FROM docker.io/library/ubuntu
=> [2/3] RUN apt-get update
=> [3/3] RUN apt-get install -y python3
लगातार होने वाले बिल्ड तेज़ होते हैं क्योंकि Docker न बदली हुई layers दोबारा उपयोग करता है.
बिल्ड फिर से चलाने पर:
=> [1/3] FROM docker.io/library/ubuntu
=> CACHED [2/3] RUN apt-get update
=> CACHED [3/3] RUN apt-get install -y python3
परिवर्तनों के साथ दोबारा बिल्ड चलाने पर:
=> [1/3] FROM docker.io/library/ubuntu
=> CACHED [2/3] RUN apt-get update
=> [3/3] RUN apt-get install -y R
कब layers cached रहती हैं, यह समझने से पता चलता है कि कभी-कभी rebuild के बाद भी images क्यों नहीं बदलतीं.
=> [1/3] FROM docker.io/library/ubuntu
=> CACHED [2/3] RUN apt-get update
=> CACHED [3/3] RUN apt-get install -y python3
इससे हम ऐसे Dockerfiles लिखते हैं जो तेज़ build होते हैं, क्योंकि हर layer को दोबारा बनना नहीं पड़ता.
नीचे दिए Dockerfile में, अगर pipeline.py बदला, तो सभी निर्देश दोबारा build होंगे:
FROM ubuntu
COPY /app/pipeline.py /app/pipeline.py
RUN apt-get update
RUN apt-get install -y python3
=> [1/4] FROM docker.io/library/ubuntu
=> [2/4] COPY /app/pipeline.py /app/pipeline.py
=> [3/4] RUN apt-get update
=> [4/4] RUN apt-get install -y python3
इससे हम ऐसे Dockerfiles लिखते हैं जो तेज़ build होते हैं, क्योंकि हर layer को दोबारा बनना नहीं पड़ता.
नीचे दिए Dockerfile में, केवल COPY निर्देश दोबारा चलाना पड़ेगा.
FROM ubuntu
RUN apt-get update
RUN apt-get install -y python3
COPY /app/pipeline.py /app/pipeline.py
=> [1/4] FROM docker.io/library/ubuntu
=> CACHED [2/4] RUN apt-get update
=> CACHED [3/4] RUN apt-get install -y python3
=> [4/4] COPY /app/pipeline.py /app/pipeline.py
Docker परिचय