March 19, 2019

How to specify ignore rules and exceptions from these rules for files and folder, that won’t be included in the build context in Docker(.dockerignore)

The .dockerignore file is the tool. It can help you to define the Docker build context you really need. Using this file, you can specify ignore rules and exceptions from these rules for files and folder, that won’t be included in the build context and thus won’t be packed into an archive and uploaded to the Docker server.

The .dockerignore file is similar to gitignore file. It is used by  the git tool. similarly to .gitignore file, it allows you to specify a pattern for files and folders that should be ignored by the Docker client when generating a build context. While .dockerignore file syntax used to describe ignore patterns is similar to .gitignore it’s not the same.
The .dockerignore pattern matching syntax is based on Go filepath.Match() function and includes some additions.
Here is he complete syntax for the .dockerignore:
Pattern:
{ term }
term:
'*' matches any sequence of non-Separator characters
'?' matches any single non-Separator character
'[' [ '^' ] { character-range } ']'
character class (must be non-empty)
c matches character c (c != '*', '?', '\\', '[')
'\\' c matches character c

character-range:
c matches character c (c != '\\', '-', ']')
'\\' c matches character c
lo '-' hi matches character c for lo <= c <= hi

additions:
'**' matches any number of directories (including zero)
'!' lines starting with ! (exclamation mark) can be used to make exceptions to exclusions
'#' lines starting with this character are ignored: use it for comments
________

Note: Using the ! character is pretty tricky. The combination of it and patterns before and after line with the ! character can be used to create more advanced rules.
Examples:
# ignore .git and .cache folders
.git
.cache

# ignore all *.class files in all folders, including build root
**/*.class

# ignore all markdown files (md) beside all README*.md other than README-secret.md
*.md
!README*.md
README-secret.md

Reference:

9 comments:


  1. Buy Instagram followers and become the popular account of social media! Quality, reliable and tracked by real accounts. Likes, comments, subscribers, viewing, viewing services. Stay on top of Youtube, twitter, facebook, instagram.
    https://buyinstagramfollowers.org/

    ReplyDelete
  2. Greetings! This is my first comment here so I just wanted to give a quick shout out and say I genuinely enjoy reading your articles. keep sharing Experience region's best desert safari in Dubai, Abu Dhabi, sightseeing tours & attractions with Clifton Tours. Book Online Today! best desert safari dubai

    ReplyDelete

  3. AWESOME ARTICLE.
    Are you a content creator on youtube and do you want increase your number of views.
    No worries, you can easily do it from India's no. 1 webiste https://www.tubeviews.in
    and submit an easy order

    ReplyDelete
  4. Greetings! This is my first comment here so I just wanted to give a quick shout out and say I genuinely enjoy reading your articles Bali bound and wondering what top things to do you can't miss? to Uluwatu, to the Gili Islands, Nusa Penida & more - in the Ultimate Bali Travel Guide blog post. Bali travel blog

    ReplyDelete
  5. It’s always nice to have a clear out once in awhile. I do Blake’s room regularly because of having to change around his clothes as he grows out of them so fast.

    sexy gaming
    slot

    ReplyDelete
  6. It’s always nice to have a clear out once in awhile. I do Blake’s room superslot

    ReplyDelete
  7. You provide both valuable and effective information on your site. Several of our resources are included in this post. I appreciate you sharing. buy views on YouTube

    ReplyDelete

I'm certainly not an expert, but I'll try my hardest to explain what I do know and research what I don't know.

My Favorite Site's List

#update below script more than 500 posts