.dockerignore - exclude directory except certain file-types

1.1k Views Asked by At

I have a .dockerignore file in which I want to exclude the entire directory /src except all .json files in that /src-Directory.

My current approach looks like this:

/src/*
!/src/**/*.json

I have also tried using /src instead of /src/*, but in both cases is the entire directory excluded and the JSON files are nowhere to be found.

1

There are 1 best solutions below

1
On

You should change the ignore file as follow:

/src/*
!/src/*.json
!/src/**/*.json

The reason is that !/src/**/*.json searches for json files inside subfolder of /src, and not in /src itself too.

Look at the official documentation if you need further info https://docs.docker.com/engine/reference/builder/#dockerignore-file .