로컬 호스트에서 도커 이미지 빌드로 여러 파일과 폴더를 복사하려고합니다.
파일은 다음과 같습니다
folder1
file1
file2
folder2
file1
file2
다음과 같이 사본을 만들려고합니다.
COPY files/* /files/
그러나 모든 파일은 / files /에 배치되며 Docker에는 하위 디렉토리 구조를 유지하고 파일을 디렉토리에 복사하는 방법이 있습니까?
답변
이 Dockerfile을 사용하여 COPY에서 별표를 제거하십시오.
FROM ubuntu
COPY files/ /files/
RUN ls -la /files/*
구조는 다음과 같습니다.
$ docker build .
Sending build context to Docker daemon 5.632 kB
Sending build context to Docker daemon
Step 0 : FROM ubuntu
---> d0955f21bf24
Step 1 : COPY files/ /files/
---> 5cc4ae8708a6
Removing intermediate container c6f7f7ec8ccf
Step 2 : RUN ls -la /files/*
---> Running in 08ab9a1e042f
/files/folder1:
total 8
drwxr-xr-x 2 root root 4096 May 13 16:04 .
drwxr-xr-x 4 root root 4096 May 13 16:05 ..
-rw-r--r-- 1 root root 0 May 13 16:04 file1
-rw-r--r-- 1 root root 0 May 13 16:04 file2
/files/folder2:
total 8
drwxr-xr-x 2 root root 4096 May 13 16:04 .
drwxr-xr-x 4 root root 4096 May 13 16:05 ..
-rw-r--r-- 1 root root 0 May 13 16:04 file1
-rw-r--r-- 1 root root 0 May 13 16:04 file2
---> 03ff0a5d0e4b
Removing intermediate container 08ab9a1e042f
Successfully built 03ff0a5d0e4b
답변
또는 “.”을 사용할 수 있습니다. * 대신 작업 디렉토리의 모든 파일을 가져 오므로 폴더와 하위 폴더를 포함하십시오.
FROM ubuntu
COPY . /
RUN ls -la /
답변
로컬 디렉토리를 이미지 내의 디렉토리로 병합 하려면 다음을 수행하십시오. 이미지 내에 이미 존재하는 파일은 삭제하지 않습니다. 동일한 이름의 파일이 이미 존재하는 경우 이미지를 로컬로 덮어 쓰고 이미지의 파일을 덮어 쓰는 파일 만 추가합니다.
COPY ./files/. /files/