2

I am building maven project using maven docker image. Maven project is very big like more than 300mb source code. So when I run docker build it needs to send all build context[source code] to Docker daemon. The issue is suppose if I have already build my maven project then source code size becomes more than 5gb including all the target directories.

So in .dockerignore I need to ignore all the /target/ directories.

I tried this but its not working

.git
**/target/*.*

2 Answers2

2

None of the answers above seemed to work for me (docker version 20.10.5). In the end, the following worked out OK:

.dockerignore:

**/target/

Here is an excerpt from the .dockerignore documentation:

Beyond Go’s filepath.Match rules, Docker also supports a special wildcard string ** that matches any number of directories (including zero). For example, **/*.go will exclude all files that end with .go that are found in all directories, including the root of the build context.

Leo
  • 1,160
  • 18
  • 31
1

It should be same as we do it in .gitignore, so to ignore target folder just use target/.

Muhammad Waqas Dilawar
  • 1,844
  • 1
  • 23
  • 34