Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.dockerignore all subfolders but not files in the folder itself

Tags:

git

docker

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
like image 959
Hedge Avatar asked Sep 15 '16 12:09

Hedge


People also ask

What is dockerignore?

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.

Can Gitignore ignore folders?

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 .

Where is .dockerignore located?

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.


2 Answers

According to documentation you can ignore only subdirectories:

.git/*/*

You don't have to manually exclude files which are directly in .git directory.

like image 101
qzb Avatar answered Oct 02 '22 20:10

qzb


Since docker 1.7, a .dockerignore file supports exception:

*/*
!FETCH_HEAD
!HEAD
like image 39
VonC Avatar answered Oct 02 '22 19:10

VonC