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
Add support for specifying .dockerignore file with -i/--ignore #12886
Comments
#dibs or sorry @tristanz are you already working on it? |
To be clear, I didn't say I wanted it - just that it could be supported. |
@runcom ^^^^ |
roger that! |
I'm not working on about it. It seems like a natural option given |
Not a maintainer (for this), I'd be +1 for this so that different Dockerfiles can exclude different parts of the build-context. I'm not sure having a single-char flag ( @tristanz Perhaps you can describe some use-cases for this feature, it may help the maintainers make a well-founded decision whether or not this is something that's wanted edit: |
Yes, I believe our use case is exactly the use case described in the named dockerfile thread: a single repo with many services that share libraries. So this is just trying to make that same use case work for real setups. Single repos like this tend to be large (which we love for many reasons!), so without --ignore-file we can't use -f and are forced to resort to prebuild scripts. |
@tristanz can you give a little more detail on these large repos? In particular, when I think about large repos with multiple sub-projects, I think to think of it as each project having their own sub-dir with their own Dockerfile but they all share a common dir that might be a sibling to each project. For example:
and in these cases I wonder if supporting symbolic links wouldn't be easier. Meaning, Also, to be clear, I'm not for or against a --ignore flag - still trying to understand the usecases. |
@duglin that's my setup exactly. I actually would much prefer symlink support to solve this. It feels less docker specific, allows be to leave my dockerfiles unchanged (sub folder build context), and I can avoid writing lots of dockerignore files. I was just under the impression that named dockerfiles were the recommended alternative. I see symlinks as the better alternative by far. |
Are symlinks supported on Windows nowadays? (Wondering) For my personal use-case, some containers are created using a volume to mount the source-code during development. Being able to exclude those files (huge number of files, not the size per-se) when starting the dev container will save lots of time. (And, yup, there are workarounds) |
I guess the main question is whether the really is no solution for multiple container git repos with shared code. This seems like a extremely common use case, but any discussion of symlinks or relative paths is not finding traction as far as I can tell. Here's the folder structure I'm thinking about:
Is there really no docker way? The best I have found so far is to simply copy shared into multiple places. |
Is it worth working on a pull request for this feature? |
It hasn't been decided on, yet, but you could try. With the chance it gets turned down :) Sometimes discussing a PR helps making a decision, so..up to you, I guess :) |
Another solution would be to look for the .dockerignore file where the Dockerfile is stored as the build directory is not necessarily the directory of which the Dockerfile is, but I would also prefer -i. |
Unfortunately, that won't work if multiple Dockerfiles are in the same directory (e.g. |
Right. Then how about a Dockerfile command to describe the corresponding .dockerignore? |
I think the proposed solution (a |
There are two thing I dislike about named dockerfiles even with dockerignore.
Dereferencing symlinks seems much more elegant. I can always see all dependencies in each folder, like single Dockerfile repositories. Security could be handled not allowing symlinks to escape the outside the local folder unless an environmental variable or flag is set. |
I take back my second point. A better convention would be to put Dockerfiles at the depth of the build context. So Dockerfile.web rather than web/Dockerfile. This would make the context clear enough. In terms of this whole issue, is there a reason why the build context is the entire folder not simply files and folders that are explicitly ADDed (plus Dockerfile/.dockerignore)? This would make multiple .dockerignore mostly unnecessary. Dereferencing symlinks also looks like a non-starter because there is already a defined behavior -- create the symlink rather than dereference it. |
I make a web project and have billions of files. Having ADD for each would create an immense amount of intermediate containers and I would need a script that built my Dockerfile for me. |
@Ralle I don't think anything would change. You just add a folder like normal. I'm just suggesting avoiding tarring and uploading things you never add. |
+1 to, in order of preference:
|
I think 1) in @pikeas list is by far the most elegant, but it is currently not easy to implement since parent images may have ONBUILD instructions. |
- .dockerignore should work according to [#12886](moby/moby#12886 (comment)). - Currently expects to be run `DOCKER_BUILDKIT=1 docker build -f Dockerfile.server ../../` from `examples/azure-websockets` folder. - This is done for isolation of docker-related stuff from the root of the repo which is supposed to host only library, not deployable example.
- Added basic Terraform setup to create a AKS cluster. - Need to add cluster manifests now. - See how to integrate with DevOps. - Adding Dockerfile. - .dockerignore should work according to [#12886](moby/moby#12886 (comment)). - Currently expects to be run `DOCKER_BUILDKIT=1 docker build -f Dockerfile.server ../../` from `examples/azure-websockets` folder. - This is done for isolation of docker-related stuff from the root of the repo which is supposed to host only library, not deployable example. - Copied TCP server into Azure. - For now to test deployments, will refactor to use HTTP/WebSockets maybe. Or not. Let's see. - Moved simple TCP example into subfolder. - This is to prepare for Azure-deployed example.
Here it says, when the BuildKit backend is used, build looks for dockerignore file that is relative to the dockerfile path, so if there are multiple dockerfiles specified in the build, it will look for multiple dockerignore files, right? |
Maintaining multiple I don't understand the motivation for holding back on adding a |
@Mugane Agreed, and it makes a lot of sense to consolidate complexity on the docker-compose level, rather than swarm (or even more complex) level. That means, all complexity in this thread and docker/compose#3729 should be doable in compose - and generally compose is a good place to consolidate arising complexity. |
Forcing people to use multiple (basically same) dockerfiles just so they can load different My situation is like this:
In such situation it seems normal to have something like this:
and when building Someone already proposed such solution in #29405 but it was discussed in the maintainers meeting and somehow this is not the right approach Somehow better approach is to:
Now we need to maintain two I just cannot get how this is better approach. |
The tests don't exhaustively test all requested combinations. In particular they say nothing about how to use this feature for dockerfiles that have meaningful names and extensions. After wasting my time exhaustively testing all combinations of naming and file placement it turns out that if you have a dockerfile |
This is unbelievable. Can't you just support passing a dockerignore and let users move on with their lives instead of this god awful file name hack? At the moment I am resorting to piping tar output to docker build because the whole configuration of what to include/ignore is a complete mess. |
@Mugane @dtheodor Podman |
Truly unbelievable. Some "ultimate design" needs to be protected? Utter and complete nonsense. Quality of life is everything -- and every argument that ultimately comes out against making users' lives easier is infuriating and Dumb. And this project is rife with it. These kinds of unforced errors are so disappointing. 8 years this ticket has been around. Yet it's a real, every day problem. Insane. 👎👎👎 |
@jpr5 See my previous comment. I moved on to alternatives |
Absolutely agree with you on that. If the -f flag can be implemented why not the -i? Instead we have this confusing workaround. Now I have to uniquely rename Dockerfiles, that are in completely different directories and make sure the dockerignore files are placed in the context root. Why not give users the flexibility by just giving us the -i/--ignore or whatever. |
Why is this issue closed? Did it get implemented? If not, who needs to be fired? |
Okay, whats the way to implement this, i have a reactjs frontend and a fastapi backend, obviously i dont want my frontend directory to be included in the build stage for my fastapi application and i am using docker-compose |
If may depend a bit on your directory structure, but when using BuildKit as builder (which is the default now), docker only sends files that you ask it to # syntax=docker/dockerfile:1
FROM alpine AS backend
COPY frontend /foo
FROM alpine as frontend
COPY backend /foo Building either stage will only send either |
my frontend directory is inside the backend directory , so i had Dockerfile.backend and Dockerfile.frontend. but what ive done now is put Dockerfile.frontend inside the frontend directory and call it Dockerfile then create a new .dockerignore file for it , then rename Dockerfile.backend to Dockerfile and then create .dockerignore. so later when building the image , ill have to set the context for frontend image different |
As several people have mentioned (@thaJeztah, @duglin) in #9707, it would be great to be able specify the .dockerignore file using -i/--ignore in conjunction with named dockerfiles. It is often difficult to use named dockerfiles because the build context becomes too large.
The text was updated successfully, but these errors were encountered: