Skip to content

Dockerfile COPY [dir1/* destdir] copies dir1/dir2/*  #29211

Open
@ashlander

Description

@ashlander

Description

Dockerfile COPY[dir1/* destdir] copies dir1/dir2/*

Steps to reproduce the issue:

  1. mkdir test; cd test
  2. mkdir -p conf/etc/apt/apt.conf.d/
  3. touch conf/etc/apt/apt.conf.d/some_file
  4. touch Dockerfile with content
FROM        ubuntu:16.04
MAINTAINER  Andrii Zhuk <https://github.com/ashlander>

# what dirs and files are inside the project
ENV root_apt_conf       conf/etc/apt/apt.conf.d
ENV root_apt_conf_file  conf/etc/apt/apt.conf.d/some_file

ENV test_conf           /var/tmp/test/conf

RUN                     mkdir -p ${test_conf}
COPY ["conf/*" ,"${test_conf}/"] # Can't be used to copy conf directory content... bug ?
# I know this is how copy should be made, but i was expecting these two will be similar, and not "go even deeper"
#COPY ["conf" ,"${test_conf}/"]
 
RUN                     ls -la ${test_conf} # present
RUN                     ls -la ${test_conf}/apt # present, where is etc gone ?!
RUN                     ls -la ${test_conf}/apt/apt.conf.d # present ?!
RUN                     ls -la ${test_conf}/etc # missing
RUN                     ls -la ${test_conf}/etc/apt # missing
RUN                     ls -la ${test_conf}/etc/apt/apt.conf.d # missing

Describe the results you received:

I have items copied like /var/tmp/test/conf/apt/apt.conf.d/some_file

Describe the results you expected:

I expect items copied like /var/tmp/test/conf/etc/apt/apt.conf.d/some_file

Output of docker version:

Client:
 Version:      1.12.3
 API version:  1.24
 Go version:   go1.6.3
 Git commit:   6b644ec
 Built:        Wed Oct 26 21:39:14 2016
 OS/Arch:      linux/amd64

Server:
 Version:      1.12.3
 API version:  1.24
 Go version:   go1.6.3
 Git commit:   6b644ec
 Built:        Wed Oct 26 21:39:14 2016
 OS/Arch:      linux/amd64

Output of docker info:

Containers: 5
 Running: 1
 Paused: 0
 Stopped: 4
Images: 188
Server Version: 1.12.3
Storage Driver: aufs
 Root Dir: /mount/store/docker/aufs
 Backing Filesystem: extfs
 Dirs: 123
 Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: host overlay null bridge
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Security Options:
Kernel Version: 3.16.0-4-amd64
Operating System: Debian GNU/Linux 8 (jessie)
OSType: linux
Architecture: x86_64
CPUs: 8
Total Memory: 7.7 GiB
Name: juk
ID: MZCE:5V4P:6J5C:K33F:V4U4:GU33:7UQB:N3VX:T3XO:3HK3:EWYL:ZCFS
Docker Root Dir: /mount/store/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
WARNING: No memory limit support
WARNING: No swap limit support
WARNING: No kernel memory limit support
WARNING: No oom kill disable support
WARNING: No cpu cfs quota support
WARNING: No cpu cfs period support
Insecure Registries:
 127.0.0.0/8

Additional environment details (AWS, VirtualBox, physical, etc.):
physical

Activity

thaJeztah

thaJeztah commented on Dec 8, 2016

@thaJeztah
Member

ping @duglin is this the same / related to #15858 ?

ashlander

ashlander commented on Dec 9, 2016

@ashlander
Author

@thaJeztah thanks for pointing me to the same thing, i believe you are right about the case. Unfortunately i was looking inside open issues for duplicates.
However this is explained but still confusing, i would vote for adding some warning example inside documentation, at least.
Thanks

duglin

duglin commented on Dec 28, 2016

@duglin
Contributor

@ashlander If you look at:https://docs.docker.com/engine/reference/builder/#/copy you'll see a "Note" that says: Note: The directory itself is not copied, just its contents.. Do you think more is needed?

ashlander

ashlander commented on Dec 28, 2016

@ashlander
Author

@duglin while i was trying to understand the reason, this note was read dozen of times, but that was not describing why destination directory contents and source directory contents do not match. In short, for such a dummies as myself, hell yea... possibly, just adding link to #15858 in documentation somewhere near.
Thanks

zentby

zentby commented on May 3, 2018

@zentby

Looks all discussions went to #15858
Any update here?

amoseev

amoseev commented on Sep 23, 2018

@amoseev

What about alternative syntax (command name or parameter)?

changed the title [-]Dockerfile COPY[dir1/* destdir] copies dir1/dir2/* [/-] [+]Dockerfile COPY [dir1/* destdir] copies dir1/dir2/* [/+] on Aug 16, 2019
Fryuni

Fryuni commented on Apr 8, 2020

@Fryuni

Any progress on this in the last few years? This requires so much hacks to work around

limitedAtonement

limitedAtonement commented on Nov 5, 2020

@limitedAtonement

As far as I can tell, there is no acceptable workaround for this problem. I understand that backwards compatibility is a requirement for any fix. I think the best backward-compatible fix for this problem would be to introduce a new Dockerfile command, cp. This has the added advantage that newcomers who don't know about "copy" (because they're accustomed to standard POSIX tools) won't have as many wasted hours and nightmares as the graybeards have had. If a new command is undesirable for some reason, perhaps adding a flag copy --not-broken /dir1/ / is acceptable?

code4happylife

code4happylife commented on Aug 16, 2022

@code4happylife

Lose a layer of directory after using COPY command in Dockerfile...

thaJeztah

thaJeztah commented on Aug 16, 2022

@thaJeztah
Member

Work is in progress in BuildKit to introduce a --parents option on ADD and COPY, which may help with this (at least for some cases); see

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @thaJeztah@duglin@ashlander@zentby@amoseev

        Issue actions

          Dockerfile COPY [dir1/* destdir] copies dir1/dir2/* · Issue #29211 · moby/moby