This was reported years ago as #1814. That issue has been marked inactive and locked, but it doesn't appear to have been solved. I'm seeing the exact same thing with Docker Desktop for Mac 2.5.0.1.
A workaround that was suggested on the original issue was to mount a volume instead of using docker cp. That workaround is not available to me in this case because I'll be running in an environment that doesn't allow the use of volumes. I'd really love to be able to simply use docker cp and have it set the user correctly.
Expected behavior
Files copied into a container with docker cp, without the -a option, should have their owner set to the default user for the container.
Actual behavior
The owner is instead being set to the user ID of the user that invoked the docker cp command (which, on my system, translates into user ID 501 in group "dialout"— exactly as reported in the original issue). In other words, it is always behaving as if the -a option were specified.
Information
MacOS Catalina 10.15.5
Docker Desktop version 2.5.0.1 - Engine 19.03.13
Steps to reproduce the behavior
Dockerfile:
FROM ubuntu:20.04
RUN groupadd -r testgroup && useradd --no-log-init -rm -g testgroup -s /bin/bash testuser
USER testuser
shell commands:
docker build -t dockerusertest .
ID=$(docker create -it dockerusertest)
docker start $ID
docker cp Dockerfile $ID:/tmp # could be any file, just using Dockerfile as an example
docker exec $ID ls -l /tmp/Dockerfile
actual output from last shell command:
-rw-r--r-- 1 501 dialout 123 Feb 10 21:14 /tmp/Dockerfile
expected output:
-rw-r--r-- 1 testuser testgroup 123 Feb 10 21:14 /tmp/Dockerfile
But I can see that the default user is being set correctly:
$ docker exec $ID whoami
testuser
This was reported years ago as #1814. That issue has been marked inactive and locked, but it doesn't appear to have been solved. I'm seeing the exact same thing with Docker Desktop for Mac 2.5.0.1.
A workaround that was suggested on the original issue was to mount a volume instead of using
docker cp. That workaround is not available to me in this case because I'll be running in an environment that doesn't allow the use of volumes. I'd really love to be able to simply usedocker cpand have it set the user correctly.Expected behavior
Files copied into a container with
docker cp, without the-aoption, should have their owner set to the default user for the container.Actual behavior
The owner is instead being set to the user ID of the user that invoked the
docker cpcommand (which, on my system, translates into user ID 501 in group "dialout"— exactly as reported in the original issue). In other words, it is always behaving as if the-aoption were specified.Information
MacOS Catalina 10.15.5
Docker Desktop version 2.5.0.1 - Engine 19.03.13
Steps to reproduce the behavior
Dockerfile:
shell commands:
actual output from last shell command:
expected output:
But I can see that the default user is being set correctly: