Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there a way to negate a pattern in .dockerignore?

Tags:

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

like image 656
Florent Valdelievre Avatar asked Nov 06 '14 09:11

Florent Valdelievre


People also ask

What should I ignore in Dockerignore?

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.

Is Dockerignore same as Gitignore?

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.

Where should I put Dockerignore?

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.

Is Dockerignore case sensitive?

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.


1 Answers

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.

like image 173
Lewis Avatar answered Sep 27 '22 18:09

Lewis