When I build an image from the local directory COPY . . in the Dockerfile copies all files except those listed in .dockerignore.
But when I build an image it by providing the URL to a git repo I have on codeberg, all files are copied, as if the .dockerignore file didn’t exist.
Is this expected behavior or a bug?
Thanks.
Sicne the dockerignore file should be in the build context, when your build context is remote, your dockerignore file should also be remote.
https://docs.docker.com/build/concepts/context/#filename-and-location
If you only want to use the Dockerfile and not the whole project, then you can directly refer to the Dockerfile like this:
docker built -f https://raw.githubusercontent.com/emmanuelgautier/awesome-dockerfiles/refs/heads/main/go/Dockerfile . -t localhost/imagename
And make sure that the required files are available locally in the local build context.
But my .dockerignore file is in the remote git repo, right next to the Dockerfile.
Please watch my asciinema video and feel free to test it yourself.
https://asciinema.org/a/STrRUPglziIu12wP
Thanks.
After wasting more time than I’d like to admit, I learned here that the .dockerignore file in the git repo is ignored. As a result, the whole git repo ends up in the build context. The only place where this is mentioned, though, is the github issue linked above ![]()
The official docs say quite the opposite! ![]()
You can use a
.dockerignorefile to exclude files or directories from the build context.
[…]
This helps avoid sending unwanted files and directories to the builder, improving build speed, especially when using a remote builder.
A remote builder is just another buildkit instance on a remote host. It is not related to a remote context source.
I am missing the information here,. This should mention the constraint it applies to.
Update: my last sentence is ambiguous. I would expect to find that kind of information in the docs. Currently it is not addressed in the docs.
Thanks for sharing it. It should indeed be mentioned in the documentation. If it is, I could not find it either.