Docker Community Forums

Share and learn in the Docker community.

Docker cp directory that starts with special character

docker

(Hvolschenk) #1

Hiya,

I am having some issues using the docker cp command to copy a directory (and it’s subdirectories) from container to host.

I am copying a node_modules directory, but the .bin and @babel directories do not get copied.

I am using a Dockerfile as follows:

FROM artifactory.armorica.gk:9000/node:carbon-alpine

WORKDIR /home/node/app
COPY package.json /home/node/app
COPY package-lock.json /home/node/app
COPY .npmrc /home/node/app

RUN npm install --quiet

RUN ls -la /home/node/app/node_modules

The ls -la is just for debugging.

When building the image I see the folders in question:

drwxr-sr-x  609 root     root         20480 Apr 10 18:26 .
drwxr-sr-x    3 root     root          4096 Apr 10 18:26 ..
drwxr-sr-x    2 root     root          4096 Apr 10 18:26 .bin
drwxr-sr-x    4 root     root          4096 Apr 10 18:26 @babel
drwxr-sr-x    3 root     root          4096 Apr 10 18:26 abab

I then do the docker cp and run an ls -la on the host machine and those folders are not present:

[installBff] drwxr-sr-x 610 root root 20480 Apr 10 20:10 .
[installBff] drwxrwxr-x   6 root root  4096 Apr 10 20:26 ..
[installBff] drwxr-sr-x   3 root root  4096 Apr 10 20:06 abab

Am I missing something or is this a bug?


(Hvolschenk) #2

To answer my own question:

The solution I came up with, for anyone stumbling across this post, is to rather map a volume to the container than to try and copy the files out:

$ docker run --name container-name -v "${pwd}/node_modules:/home/node/app/node_modules" image-name