Skip to content

docker cp is *still* not setting correct UID/GID #5329

@eli-darkly

Description

@eli-darkly

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.

  • I have tried with the latest version of Docker Desktop
  • [n/a] I have tried disabling enabled experimental features
  • I have uploaded Diagnostics
  • Diagnostics ID: 3C4F0343-3E62-4F5C-869B-63D36EA001E7/20210210211014

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions