admin管理员组

文章数量:1123557

I am using docker container to build my application and the ownership of the files and folders are non-root users..

I need to copy files from my physical local machine to the docker container and the ownership of files are root. here is the command I used to copy files from local to the docker container

docker cp resources <container-id>:/var/lib

The ownership of the resources folder I copied from local machine to the docker container is root, how can I change it to non-root ownership? The docker container don't have rights to perform chown command.

Is it possible to use "docker cp" command with ownership?

My docker container do have dockerfile and the dockerfile doesn't have anything regards to this. I just want to use non-root ownership of the files I copied from localhost to the docker container.

I am using docker container to build my application and the ownership of the files and folders are non-root users..

I need to copy files from my physical local machine to the docker container and the ownership of files are root. here is the command I used to copy files from local to the docker container

docker cp resources <container-id>:/var/lib

The ownership of the resources folder I copied from local machine to the docker container is root, how can I change it to non-root ownership? The docker container don't have rights to perform chown command.

Is it possible to use "docker cp" command with ownership?

My docker container do have dockerfile and the dockerfile doesn't have anything regards to this. I just want to use non-root ownership of the files I copied from localhost to the docker container.

Share Improve this question edited 20 hours ago xxestter asked 20 hours ago xxestterxxestter 4998 silver badges24 bronze badges 11
  • Please edit your question and add details of your docker configuration and how exactly you copy the files and how exactly you tried to fix the problem. Copy & paste the code instead of describing it. – Bodo Commented 20 hours ago
  • @Bodo I have edited my issue, hopefully it will helps. thank yoou very much – xxestter Commented 20 hours ago
  • It is still not clear why you need to copy the files and why you need the files to have a non-root ownership. Add more details what you want to achieve. There might be a different way. – Bodo Commented 20 hours ago
  • 1 Is there a reason you cannot use mounted volumes for this? – Botje Commented 20 hours ago
  • Looks like an XY problem – Bodo Commented 20 hours ago
 |  Show 6 more comments

1 Answer 1

Reset to default 0

You can use the standard approach of piping tar:

tar c resources | docker exec -i $container_name tar x -C /var/lib --uid $uid --gid $gid

where $uid and $gid are the non-root user and group ids used inside the container.

本文标签: linuxchown when docker cp from localhost to containerStack Overflow