How can I exclude a sub-directory with a .dockerignore file

Docker

Docker Problem Overview


I want to exclude a sub-directory using a .dockerignore file, but I don't know what the syntax should be, and there are no examples anywhere.

I have a sub-directory vendor/bundle.

I've put

vendor/bundle in the .dockerignore file. Also vendor/bundle/ and /vendor/bundle but none of them seem to work.

(Also, the .dockerignore file is being found, but just not working.)

Docker Solutions


Solution 1 - Docker

There is a shorter and easier method to write your .dockerignore :

vendor/bundle/**/*
vendor/bundle

Solution 2 - Docker

With the help of PHPStorm - Click right on project -> then you have an option ".i*" -> then select .dockerignore. It will ask you what type of project you have. I search for symfony PHP in my case. Then it will automatically create a template with all the files that need to be excluded.

After this project seemed to be working more efficiently :)!

Solution 3 - Docker

This is the only answer I've been able to find, and it has worked and therefore solved my problem.

The bad thing is that it is very hacky.

I've put the following in my .dockerignore file for every sub-directories I want to recursively exclude.

vendor/bundle/*/*/*/*/*/*/*/*
vendor/bundle/*/*/*/*/*/*/*
vendor/bundle/*/*/*/*/*/*
vendor/bundle/*/*/*/*/*
vendor/bundle/*/*/*/*
vendor/bundle/*/*/*
vendor/bundle/*/*
vendor/bundle/*
vendor/bundle

This excludes all files and directories from vendor/bundle down to 7 levels further. (Not sure the order matters.)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLukas OberhuberView Question on Stackoverflow
Solution 1 - DockersebthemonsterView Answer on Stackoverflow
Solution 2 - DockermarmureanuwebView Answer on Stackoverflow
Solution 3 - DockerLukas OberhuberView Answer on Stackoverflow