I am trying to negate a pattern in a .dockerignore. The Globbing is done using Go's filepath.Match rules. After checking the source, it seems we can negate a pattern by using ^ character.
.dockerfile
*
^Dockerfile
^web-app/dist
However, when i docker build, I have the following error:
Dockerfile was excluded by .dockerignore pattern '*'
Do you know if its possible to accomplish what I want ?
Thanks
dockerignore file is used to ignore files and folders when you try to build a Docker Image. You can specify the list of files and directories inside the . dockerignore file.
dockerignore file is very similar to the . gitignore file in that it allows you to specify a list of files or directories that Docker is to ignore during the build process.
From the official docs of docker for . dockerignore: Before the docker CLI sends the context to the docker daemon, it looks for a file named . dockerignore in the root directory of the context.
dockerignore file is case-insensitive on Windows and case-sensitive on Linux (and thus likely MacOS). From the Docker documentation: The CLI interprets the . dockerignore file as a newline-separated list of patterns similar to the file globs of Unix shells.
As of version 1.7.0, this is now possible.
Negating with !
now works as you would expect and is documented in the official Dockerfile reference.
Here's an example taken from the link above:
*/temp*
*/*/temp*
temp?
*.md
!LICENSE.md
The line !LICENSE.md
will cause LICENSE.md to be included in the Docker build context despite the *.md
rule.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With