2

I want to copy a folder from docker container to my machine. I'm looking at this question.

So here is my command:

sudo docker cp 2f6aca7f2748:/root/scripts/ .

I got the following error:

mkdir /home/***/scripts: permission denied

I try mkdir scripts, and it is OK (of course). What could be the problem here?


Update

Some more context: I'm using a NIS account, shared between both my desktop and server. However, docker is in the server, and I want to copy folder from host to my local folder on server.

qsp
  • 1,252
  • 1
  • 13
  • 30

2 Answers2

0

In https://docs.docker.com/engine/reference/commandline/cp/#extended-description

it says :

The cp command behaves like the Unix cp -a command in that directories are copied recursively with permissions preserved if possible. Ownership is set to the user and primary group at the destination. For example, files copied to a container are created with UID:GID of the root user. Files copied to the local machine are created with the UID:GID of the user which invoked the docker cp command.

Thats maybe the cause this problem.

Fahri
  • 422
  • 3
  • 12
0

As a follow up to @Fahri's solution here.

You need ownership for the destination folder,

Since I was about to wipe the machine anyways, I just set the ownership of the folder to any user with the following command.

sudo chmod -R a+rwX directory/

remember to not do this if you plan to keep the machine, refer to this answer for proper permissions.

Blaine
  • 333
  • 2
  • 15