Every time you run docker build, the client (where your cli is) sends a new build context (the files you use to build the image) to the Docker Daemon/Server (where the building happens). The Daemon/Server can exist locally or it can exist over a network. Taking more files to the Daemon/Server increases the load and time to archive and send. Try avoid adding files which are not needed to build your image eg dist, bin, packages, node_modules

When you build an image and the Dockerfile has an ADD . or COPY . it may include unnecessary files eg .git or privatekeys. This may lead to exposing secrets through your image.

? matches a single character. eg to ignore files with a single character difference:

file_?.md

* matches and number of characters. eg to ignore any file name with extension md:

*.md

** matches and number of directories eg to ignore md files in any directory

**/*.md

/ matches a specific directory eg to ignore a directory

/bin/debug 

! Sets an exception eg to ignore all md files, except all which start with important, except important_ideas.md

*.md
!important*.md
important_ideas.md
# important_ideas.md will be ignored because it comes after the exception (its an exception to the exception)

Here are some examples of common ignores:

.dockerignore

# ignore build files
[Bb]in/
[Oo]bj/
dist
node_modules/
packages
*.log

# ignore visual studio files
.vscode
*.suo
*.user
*.sln.docstates
*.vspx
*.vsp
*.psess
class="mb-3"> 

# ignore git files
.git
.gitignore
README.md
LICENSE

# ignore docker files
Dockerfile*
docker-compose*
.dockerignore

Check out these links for more info:

My Docker Samples