I would like to copy whitelisted folders from filesystem into target container.
Basically I'd like to perform "complex" operation cp -r app vendor target
, where target
is a Docker container.
I have simple Docker file:
FROM alpine
COPY app/* /www/
COPY vendor /www/
For reasons unknown the first command doesn't copy the app
directory itself. It seems that Docker doesn't distinguish the difference between app
and app/
which is quite irritating.
For testing purposes I've created following structure:
.
├── app
│ ├── foo
│ └── second
│ └── barf
├── Dockerfile
└── vendor
└── bar
docker build -t test . && docker run -it test ash
:
Result? Directory structure is not kept and parent directories not copied.
/www/
├── bar
├── barf
└── foo
docker info
:
Server Version: 1.12.1
Storage Driver: overlay2
Backing Filesystem: extfs
Can anyone explain me why Docker's COPY . /target
and COPY app/* /target
behaves differently? What's the motivation? Why Docker doesn't used standard semantic of UNIX cp
command?
Generally, COPY instruction copy files and/or directories from "/app" and adds them to the container at path "/www/". If you want to have a "app" directory inside of "/www/" then your COPY instruction should looks like:
COPY /app /www/app/
You can read more about COPY instruction in documentation. Here I paste explanation of this behaviour from it:
If is a directory, the entire contents of the directory are copied, including filesystem metadata. Note:The directory itself is not copied, just its contents.
Regarding to your update: COPY . /target
and COPY app /target
behaves the same. It takes entire contents from source directory ( from app
or from .
directory ) and copy it to the /target
directory.
You can see slightly different behaviour when you use wildcards, eg. COPY app/* /www/
. It copy all files from app/
to /www/
but then it treat every single directory from app/
like a source and copy its contents to /www/
.
Why in Docker COPY
is not implemented in the same way like it is in UNIX's cp
command? I don't know, but if you want you can create pull request with own implementation :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With