New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dockerfile COPY with file globs will copy files from subdirectories to the destination directory #15858
Comments
Updated original message with output from |
I've had this on 1.6.2 and 1.8 for those googling: if you're having issues with COPY * /src try COPY / /src |
@jfchevrette I think I know why this is happening. I'm not thrilled with that fact that COPY doesn't preserve the top-level dir but its been that way for a while now. You can try to make this less painful by copying one level higher in the src tree, if possible. |
I'm pretty confident that @duglin in right and it could be very risky to change that behavior. many dockerfiles may break or simply copy inuntended stuff. However I'd argue that for the long run it would be better if COPY was following the way tools such as cp or rsync handle globs & trailing slashes on folders. It's definitely not expected for COPY to copy files from a subfolder matching dir/* into the destination IMO |
@jfchevrette yep - first chance we get we should "fix" this. |
@duglin so, closing means it will not get fixed? |
@tugberkugurlu yup, at least for now. There's work underway to redo the entire build infrastructure and when we do that is when we can make COPY (or its new equivalent) act the way it should. |
@duglin thanks. Is it possible to keep this issue open and update the status here? Or is there any other issue for this that I can subscribe to? |
@tugberkugurlu I thought we had an issue for "client-side builder support" but I can't seem to find it. So all we may have is what the ROADMAP ( https://github.com/docker/docker/blob/master/ROADMAP.md#22-dockerfile-syntax ) says. As for keeping the issue open, I don't think we can do that. The general rule that Docker has been following is to close any issue that isn't actionable right away. Issues for future work are typically closed and then reopened once the state of things change such that some action (PR) can be taken for the issue. |
@duglin This is very serious issue, you shouldn't just close it because the problem was introduced in 0.1 release. It would be more appropriate to target this for 2.0 release (milestones are on github too). I guess most people use:
and blacklist all other folders in
It's quite hard for me to imagine that someone would actually use |
@duglin This is a ridiculous and infuriating issue and should not be closed. The |
@tjwebb there's still an open issue #29211. This can only be looked into if there's a way to fix this that's fully backward compatible. We're open to suggestions if you have a proposal how this could be implemented (if you do, feel free to write this up, and open a proposal, linking to this issue). Note that there's already a difference between (for example), OS X, and Linux in the way
OS X:
On Ubuntu (/bin/sh)
diff --git a/macos.txt b/ubuntu.txt
index 188d2c3..d776f19 100644
--- a/macos.txt
+++ b/ubuntu.txt
@@ -11,15 +11,17 @@
│ ├── dir2
│ └── file1
├── target2
-│ ├── dir1
-│ │ └── dir1-file1
-│ ├── dir2
-│ └── file1
+│ └── source
+│ ├── dir1
+│ │ └── dir1-file1
+│ ├── dir2
+│ └── file1
├── target3
-│ ├── dir1
-│ │ └── dir1-file1
-│ ├── dir2
-│ └── file1
+│ └── source
+│ ├── dir1
+│ │ └── dir1-file1
+│ ├── dir2
+│ └── file1
├── target4
│ ├── dir1
│ │ └── dir1-file1
@@ -30,6 +32,8 @@
│ │ └── dir1-file1
│ └── dir2
└── target6
- └── dir1-file1
+ ├── dir1
+ │ └── dir1-file1
+ └── dir2
-20 directories, 12 files
+24 directories, 12 files |
Make a new command CP and get it right this time please. |
I would echo the above, this must have wasted countless development hours, its extremely un-intuitive. |
+1 from me. This is really stupid behavior and could easily be remedied by just adding a CP command that performs how COPY should have. "Backwards compatibility" is a cop out |
The TL;DR version: Don't use |
COPY only able copy it's subfolder . |
Just spent countless hours on this... Why does this even work this way? |
I'm using Paket and want to copy the following in the right structure:
And by doing
How about adding a |
COPY . /destination preserves sub-folders. |
Three years and this is still an issue :-/ |
Can we get an ETA, when this will be fixed |
not an issue... |
True, no longer an issue after you fume for half a day and end up here. Sure :) We really need a new CP command or a Top points if we also show a warning on image build, like: |
I'm looking for this for copying across nested lerna package.json files in subdirectories to better utilise Something like this would be great:
|
@automaton82 @rjgotten looks like this proposal may address that use-case; #35639 (also see moby/buildkit#396, and this comment, which describes things more in-depth; #38710 (comment) |
The band-aid workaround you proposed worked very well, so I thank you for that. It solved the problem for me. I only had to modify the find slightly to accommodate the fact that we have a complicated build structure with other project types and files. It is now saving 100+ seconds of NuGet build refresh. Adding a new flag to the |
@thaJeztah Buildkit of course is -- with no offense meant to the parties involved; it's a complete rework after all -- dragging its feet. And meanwhile many users continue to suffer the inadequacies of the I'm very happy to see something that resembles a formal proposal somehow coming together and hopefully something coming of it. |
It was also fun to learn the other day (according to official docs) that the .dockerignore file similarly uses Go's file finding/matching/whatever-you'd-call-it. I mean I get it, all this is written in Go... but when decent globbing has been a staple in so many other places (node-land, gulp, even the normal .gitignore!), it just seems crazy they went this way :P |
@duglin Please reopen this issue thanks :) |
If this is not fixed, why closed? It will save a lot of juice if gets fixed. |
How about this syntax to avoid breaking changes? COPY modules/*/package*.json ./modules/* |
Any Updates? |
We did: * Add Dockerfile in `back/` folder for docker container `backend`. Now it will build the node_modules in image. It will be helpful for those who do not have tool yarn and reduce the difficulty of running. * Move source files from `back/` to `back/src`. Because Dockerfile's `COPY` cannot just copy directory. [More info][github-moby-dockerfile-stupid-copy]. And that's why we also change some files with new path to those source files. * Add `depends_on` keys in `docker-compose.yml` [github-moby-dockerfile-stupid-copy]: moby/moby#15858
We did: * Add Dockerfile in `back/` folder for docker container `backend`. Now it will build the node_modules in image. It will be helpful for those who do not have tool yarn and reduce the difficulty of running. * Move source files from `back/` to `back/src`. Because Dockerfile's `COPY` cannot just copy directory. [More info][github-moby-dockerfile-stupid-copy]. And that's why we also change some files with new path to those source files. * Add `depends_on` keys in `docker-compose.yml` [github-moby-dockerfile-stupid-copy]: moby/moby#15858
It's just shameful at this point, it's 2022 and people still have to deal with this. |
This would make my Dockerfile SO much simpler. Seven COPY commands in my current file could be just one. Just create a new |
Another plea to please, please just add
This seems like it would be a trivially easy feature to implement. EDIT: Sadly the |
Omg, what is the problem to just add new flag to the COPY command? Is the architecture of buildkit so weird, that it is so hard to just extend functionality of the COPY command or even create a new command as it was proposed in this thread? Lots of developers write tons of example for you why this is so wanted feature, but you ...just close the ticket? This is ridiculous! |
This happens most of the time when a product becomes one in the market. |
Same happened with postman not supporting GRPC for years. Just no other so much developed product. |
For those .Net folks still suffering due to the lack of this feature, another workaround: If you have CPVM enabled and are not enabling project-specific version overrides, and you know the target frameworks your app uses, then you can just copy over your
where
This avoids the need to depend on repository structure and avoids slowly copying over the whole repository, and avoids this buildkit nightmare, but is not a silver bullet as it still downloads more packages than the app needs in a monorepo and only works with non-overridable CPVM. I imagine Paket users also have an analogous workaround, not needing the dummy project created. |
Hi, I have a solution using bash in one line for you and also I hope you all can adapt the code to fit your needs:
|
Thanks guys! It helped me a lot and I finally wrote multi layer build with cached restore results. I developed the idea of restoring project structure inside a temporary docker container. Solution contains *.sln file which already knows about project structure. So with little help of bash we can restore folders hierarchy. Here some samples:
|
@warning-explosive , nice solution. Essentially what my global tool (dotnet-references) does (docs), but without having to install a global tool :) Can you parameterize that script to accept the sln file so that this could be used across multiple solutions? And what do you mean by "don't forget replace windows backslashes!"? Are you replacing all |
About windows backslashes, you got it right and the bash script above actually replaces them. I've just wanted to emphasize this possible compatibility issue between platforms. Parametrization with solution file name also possible, but I'm not going to do this soon. |
While it's possible to solve the
Since the file names are identical, you have to copy the COPY ./Project1/packages.lock.json ./Project1/
COPY ./Project2/packages.lock.json ./Project2/ I don't think think the design of the .NET project structure is inherently flawed. It seems quite reasonable to expect build tooling to be able to handle this scenario. |
See moby/buildkit#3001, should resolve this use case. |
Description of problem:
When using
COPY
in aDockerfile
and using globs to copy files & folders, docker will (sometimes?) also copy files from subfolders to the destination folder.Environment details:
Local setup on OSX /w boot2docker built with docker-machine
How to Reproduce:
Context
Dockerfile
Actual Results
Expected Results
The resulting image should have the same directory structure from the context
The text was updated successfully, but these errors were encountered: