Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.dockerignore fails to include files in subdirectories with !**/*.extension pattern

Tags:

I'm having trouble with the .dockerignore file. This is my project structure:

file.sh
file.js
file.go
file.py
subdir/
    file2.go
    file2.py
.dockerignore
Dockerfile

According to the .dockerignore documentation:

(...) you may want to specify which files to include in the context, rather than which to exclude. To achieve this, specify * as the first pattern, followed by one or more ! exception patterns.

And:

Lines starting with ! (exclamation mark) can be used to make exceptions to exclusions.

Finally:

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.

Based on that, this is my .dockerignore file:

# ignore everything
*

# whitelist
# ---------

# python files
!**/*.py

When I build and run the container and inspect the files, I get this:

file.py

The subdir directory is missing, subdir/file2.pyshould be included. It works if I add !subdir/**/.py to my .dockerignore, but the idea is to include any .py file in any subdirectory.

This is the file structure that should be present in the container:

file.py
subdir/
    file2.py

What's going on here?

like image 236
DaniGuardiola Avatar asked Jun 14 '19 08:06

DaniGuardiola


1 Answers

I found a few issues that mention this exact problem, like these:

Exception patterns in .dockerignore do not support wildcard directories dockerignore does not respect the "special wildcard **" (comment)

And it seems like it's not gonna be fixed any time soon :(

like image 198
DaniGuardiola Avatar answered Sep 28 '22 17:09

DaniGuardiola