programing

도커 파일 복사 보관 하위 디렉터리 구조

kingscode 2023. 8. 9. 22:08
반응형

도커 파일 복사 보관 하위 디렉터리 구조

로컬 호스트에서 도커 이미지 빌드에 여러 파일과 폴더를 복사하려고 합니다.

파일은 다음과 같습니다.

folder1/
    file1
    file2
folder2/
    file1
    file2

저는 다음과 같이 복사본을 만들려고 합니다.

COPY files/* /files/

하지만, 모든 파일은folder1/그리고.folder2/에 배치됩니다./files/폴더 없이 직접:

files/
    file1
    file2

Docker에서 하위 디렉터리 구조를 유지하고 파일을 해당 디렉터리에 복사할 수 있는 방법이 있습니까?다음과 같이:

files/
    folder1/
        file1
        file2
    folder2/
        file1
        file2

다음 도커 파일을 사용하여 복사에서 별을 제거합니다.

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 ./local-path/. /image-path/

저는 저를 위해 일할 수 있는 어떤 대답도 얻을 수 없었습니다.작업 도커 파일이 다음과 같이 보이도록 현재 디렉터리에 점을 추가해야 했습니다.

FROM ubuntu 
WORKDIR /usr/local
COPY files/ ./files/

또한 사용RUN ls나에게 효과가 없었고 그것을 작동시키는 것이 정말로 관여된 것처럼 보이는 것을 확인하는 것, 도커 파일에 있는 것을 확인하는 훨씬 쉬운 방법은 대화형 셸을 실행하고 그 안에 있는 것을 확인하는 것입니다.docker run -it <tagname> sh.

동일한 디렉토리 구조로 원본 디렉토리를 완전히 복사하려면 별표(*)를 사용하지 마십시오.아래와 같이 도커 파일에 COPY 명령어를 작성합니다.

COPY . destinatio-directory/ 

언급URL : https://stackoverflow.com/questions/30215830/dockerfile-copy-keep-subdirectory-structure

반응형