Dockerfileのコピーはサブディレクトリ構造を維持する 質問する

Dockerfileのコピーはサブディレクトリ構造を維持する 質問する

ローカルホストからビルドされた Docker イメージに、いくつかのファイルとフォルダーをコピーしようとしています。

ファイルは次のようになります:

folder1/
    file1
    file2
folder2/
    file1
    file2

次のようなコピーを作成しようとしています:

COPY files/* /files/

ただし、 および のすべてのファイルはfolder1/、フォルダーなしで直接 にfolder2/配置されます。/files/

files/
    file1
    file2

Docker でサブディレクトリ構造を維持しながら、ファイルをディレクトリにコピーする方法はありますか? 次のようになります:

files/
    folder1/
        file1
        file2
    folder2/
        file1
        file2

ベストアンサー1

次の 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

おすすめ記事