Docker'a Giriş
Tim Sangster
Software Engineer @ DataCamp
COPY talimatı yerel makinemizden, oluşturduğumuz imaja dosya kopyalar:
COPY <src-path-on-host> <dest-path-on-image>
COPY /projects/pipeline_v3/pipeline.py /app/pipeline.py
docker build -t pipeline:v3 .
...
[4/4] COPY ./projects/pipeline_v3/pipeline.py /app/pipeline.py
Hedef yol bir dosya adı içermiyorsa, özgün dosya adı kullanılır:
COPY /projects/pipeline_v3/pipeline.py /app/
Kaynak yolunda dosya adı belirtmezseniz, klasörün tüm içeriği kopyalanır.
COPY <src-folder> <dest-folder>
COPY /projects/pipeline_v3/ /app/
COPY /projects/pipeline_v3/ /app/ komutu pipeline_v3/ altındakilerin tümünü kopyalar:
/projects/
pipeline_v3/
pipeline.py
requirements.txt
tests/
test_pipeline.py
/init.py
/projects/
Dockerfile
pipeline_v3/
pipeline.py
Geçerli çalışma dizinimiz projects/ ise:
init.py dosyasını imaja kopyalayamayız.
docker build -t pipeline:v3 .
=> ERROR [4/4] COPY ../init.py / 0.0s
failed to compute cache key: "../init.py" not found: not found
Yerel dizinden kopyalamak yerine, dosyalar genellikle imaj oluştururken indirilir:
RUN curl <file-url> -o <destination>
RUN unzip <dest-folder>/<filename>.zip
RUN rm <copy_directory>/<filename>.zip
RUN curl <file_download_url> -o <destination_directory>/<filename>.zip \
&& unzip <destination_directory>/<filename>.zip -d <unzipped-directory> \
&& rm <destination_directory>/<filename>.zip
| Kullanım | Dockerfile Talimatı |
|---|---|
| Ana makinadan imaja dosya kopyalama | COPY <src-path-on-host> <dest-path-on-image> |
| Ana makinadan imaja klasör kopyalama | COPY <src-folder> <dest-folder> |
| Dockerfile'ı derlediğimiz üst dizinden kopyalayamayız |
Tek bir RUN talimatında indirip, açıp, temizleyerek imajları küçük tutun:
RUN curl <file_download_url> -o <destination_directory> \
&& unzip <destination_directory>/<filename>.zip -d <unzipped-directory> \
&& rm <destination_directory>/<filename>.zip
Docker'a Giriş