Reputation: 15770
I have directory structure like this:
opt
- dcmtk-3.6.5-linux-x86_64-static
| - bin
| - etc
| - share
In each of there subdirectories there are also some files.
In Dockerfile
I have line
COPY opt/* /opt/
But when I create container from this image, and run /bin/bash
, and go to /opt
and run ls -al
I can see there is only bin
directory, with it's content. No dcmtk-3.6.5-linux-x86_64-static
directory, no other subdirectories like etc
or share
.
There are also some other files I keep in opt
, those are copied just as expected.
Why isn't whole dcmtk-3.6.5-linux-x86_64-static
copied?
Upvotes: 1
Views: 2594
Reputation: 19421
As the documentation says:
If <src> is a directory, the entire contents of the directory are copied, including filesystem metadata.
So you should use the following:
COPY opt /opt
Just leave out the /*
and specify only the directory.
Edit 01.10.2020:
Just tried again with the following setup:
ls -lR
total 8
-rw-r--r-- 1 peter staff 34 1 Okt 13:06 Dockerfile
drwxr-xr-x 4 peter staff 128 1 Okt 13:01 opt
./opt:
total 0
drwxr-xr-x 2 peter staff 64 1 Okt 13:01 emptydir
drwxr-xr-x 4 peter staff 128 1 Okt 13:01 foo
./opt/emptydir:
./opt/foo:
total 0
drwxr-xr-x 3 peter staff 96 1 Okt 13:01 bar
-rw-r--r-- 1 peter staff 0 1 Okt 13:01 foo.txt
./opt/foo/bar:
total 0
-rw-r--r-- 1 peter staff 0 29 Sep 19:15 bar.txt
Dockerfile:
FROM busybox:latest
COPY opt /opt
building the image:
docker build -t so-test .
Sending build context to Docker daemon 5.12kB
Step 1/2 : FROM busybox:latest
---> 6858809bf669
Step 2/2 : COPY opt /opt
---> Using cache
---> f6f2692b571a
Successfully built f6f2692b571a
Successfully tagged so-test:latest
running the container:
docker run -it so-test /bin/sh
/ #
and checking what's in there:
# ls -lR /opt
/opt:
total 8
drwxr-xr-x 2 root root 4096 Oct 1 11:01 emptydir
drwxr-xr-x 3 root root 4096 Oct 1 11:01 foo
/opt/emptydir:
total 0
/opt/foo:
total 4
drwxr-xr-x 2 root root 4096 Oct 1 11:01 bar
-rw-r--r-- 1 root root 0 Oct 1 11:01 foo.txt
/opt/foo/bar:
total 0
-rw-r--r-- 1 root root 0 Sep 29 17:15 bar.txt
So the whole directory structure was copied, including the empty directory. There must be something interfering in you setup
Upvotes: 1
Reputation: 44615
Extracts from the documentation (in relevant order for my answer)
If multiple <src> resources are specified, either directly or due to the use of a wildcard, then <dest> must be a directory, and it must end with a slash /
[...]
If <src> is a directory, the entire contents of the directory are copied, including filesystem metadata.
Note: The directory itself is not copied, just its contents.
Solution:
COPY opt /opt/
Upvotes: 1