Skip to content

COPY --from does not preserve permissions on top folder #38710

@stellirin

Description

@stellirin

Using COPY --from to copy an entire folder does not preserve the permissions of the top folder. Example:

FROM centos:7 AS prepare

RUN mkdir -p /opt/test \
 && echo "Before chmod" \
 && ls -l /opt/ \
 && touch /opt/test/file \
 && chmod -R g=u /opt/test \
 && echo "After chmod" \
 && ls -l /opt/ \
 && ls -l /opt/test/

FROM centos:7

COPY --from=prepare /opt/test /opt/test

RUN echo "After copy" \
 && ls -l /opt/ \
 && ls -l /opt/test/

After copy I expect:

ls -l /opt/
drwxrwxr-x 2 root root 4096 Feb 11 22:06 test

After copy I have:

ls -l /opt/
drwxr-xr-x 2 root root 4096 Feb 11 22:06 test

Docker version:

Client: Docker Engine - Community
 Version:           18.09.1
 API version:       1.39
 Go version:        go1.10.6
 Git commit:        4c52b90
 Built:             Wed Jan  9 19:34:26 2019
 OS/Arch:           windows/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.1
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.6
  Git commit:       4c52b90
  Built:            Wed Jan  9 19:41:49 2019
  OS/Arch:          linux/amd64
  Experimental:     true

Docker info:

Containers: 6
 Running: 1
 Paused: 0
 Stopped: 5
Images: 112
Server Version: 18.09.1
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host ipvlan macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 9754871865f7fe2f4e74d43e2fc7ccd237edcbce
runc version: 96ec2177ae841256168fcf76954f7177af9446eb
init version: fec3683
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.125-linuxkit
Operating System: Docker Desktop
OSType: linux
Architecture: x86_64
CPUs: 6
Total Memory: 5.8GiB
Name: docker-desktop
ID: MXHC:RWZ7:3NKV:OCY4:EI6P:ZB4D:27NN:2SQE:3RDE:5MAO:VYQI:UW3R
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 54
 Goroutines: 101
 System Time: 2019-02-11T22:16:18.8130036Z
 EventsListeners: 1
Registry: https://index.docker.io/v1/
Labels:
Experimental: true
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false
Product License: Community Engine

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/builderBuildkind/enhancementEnhancements are not bugs or new features but can improve usability or performance.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions