I've got a folder structure like below. I want to ignore all subfolders (and all their content) of .git
but include all files which are directly in .git
(e.g. FETCH_HEAD and HEAD).
How do I write that in the .dockerignore
file.
.git
├── COMMIT_EDITMSG
├── FETCH_HEAD
├── HEAD
├── description
├── hooks
│ ├── applypatch-msg.sample
│ ├── commit-msg.sample
│ ├── post-update.sample
│ ├── pre-applypatch.sample
The . 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. This can come in really handy in certain instances.
gitignore file is a plain text file where each line contains a pattern for files/directories to ignore. Generally, this is placed in the root folder of the repository, and that's what I recommend. However, you can put it in any folder in the repository and you can also have multiple .
The . dockerignore file is a special file that can be placed within the build context directory. The build context directory is the directory that we specify at the end of a docker build command.
According to documentation you can ignore only subdirectories:
.git/*/*
You don't have to manually exclude files which are directly in .git
directory.
Since docker 1.7, a .dockerignore
file supports exception:
*/*
!FETCH_HEAD
!HEAD
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With