Docker 입문
Tim Sangster
Software Engineer @ DataCamp
COPY 지시어는 로컬 머신의 파일을 빌드 중인 이미지로 복사합니다:
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
대상 경로에 파일명이 없으면 원래 파일명이 사용됩니다:
COPY /projects/pipeline_v3/pipeline.py /app/
src-path에 파일명을 지정하지 않으면 폴더 내용 전체가 복사됩니다.
COPY <src-folder> <dest-folder>
COPY /projects/pipeline_v3/ /app/
COPY /projects/pipeline_v3/ /app/는 pipeline_v3/ 아래의 모든 항목을 복사합니다:
/projects/
pipeline_v3/
pipeline.py
requirements.txt
tests/
test_pipeline.py
/init.py
/projects/
Dockerfile
pipeline_v3/
pipeline.py
현재 작업 디렉터리가 projects/ 폴더일 때:
이미지로 init.py를 복사할 수 없습니다.
docker build -t pipeline:v3 .
=> ERROR [4/4] COPY ../init.py / 0.0s
failed to compute cache key: "../init.py" not found: not found
로컬에서 복사하는 대신, 빌드 중 이미지 안에서 파일을 다운로드하는 경우가 많습니다:
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
| 용도 | Dockerfile 지시어 |
|---|---|
| 호스트에서 이미지로 파일 복사 | COPY <src-path-on-host> <dest-path-on-image> |
| 호스트에서 이미지로 폴더 복사 | COPY <src-folder> <dest-folder> |
| Dockerfile 빌드 경로의 상위 디렉터리에서는 복사 불가 |
하나의 RUN 지시어에서 다운로드, 압축 해제, 정리를 수행해 이미지를 작게 유지하십시오:
RUN curl <file_download_url> -o <destination_directory> \
&& unzip <destination_directory>/<filename>.zip -d <unzipped-directory> \
&& rm <destination_directory>/<filename>.zip
Docker 입문