🌐
GitHub
github.com › garygitton › dockerignore
GitHub - garygitton/dockerignore: Collection of template for dockerignore
Collection of template for dockerignore. Contribute to garygitton/dockerignore development by creating an account on GitHub.
Starred by 35 users
Forked by 6 users
🌐
GitHub
github.com › themattrix › python-pypi-template › blob › master › .dockerignore
python-pypi-template/.dockerignore at master · themattrix/python-pypi-template
Template for quickly creating a new Python project and publishing it to PyPI. - python-pypi-template/.dockerignore at master · themattrix/python-pypi-template
Author   themattrix
🌐
Reddit
reddit.com › r/docker › a collection of .dockerignore templates
A collection of .dockerignore templates : r/docker
November 4, 2020 - When building Python projects, I don't want my entire local virtualenv folder to get copied to the server. That can be a lot of extra data that I don't need. For this reason, I add my venv/ directory to my .dockerignore file the first thing.
🌐
.dockerignore
dockerignore.com
.dockerignore Templates for Frameworks, Languages & Tools
Curated .dockerignore templates for popular frameworks, languages, and tools. Find the perfect template for your project in seconds.
🌐
Medium
medium.com › nerd-for-tech › bigger-dockerignore-smaller-docker-images-49fa22e51c7
Bigger .dockerignore, Smaller Docker Images | by Starlight Romero | Nerd For Tech | Medium
July 26, 2021 - Much like a .gitignore file which defines the files that we want git to ignore, a .dockerignore file defines the files that we want Docker to ignore. But why do we want Docker to ignore certain files? Going back to wanting smaller images, a smaller image means faster build times when we run docker run or docker-compose up.
🌐
GitHub
gist.github.com › KernelA › 04b4d7691f28e264f72e76cfd724d448
.dockerignore example for Python projects · GitHub
.dockerignore example for Python projects. GitHub Gist: instantly share code, notes, and snippets.
Find elsewhere
🌐
Rdrr.io
rdrr.io › github › jimbrig › jimstemplates › man › create_dockerignore.html
create_dockerignore: Create .dockerignore from template in jimbrig/jimstemplates: Collection of templates
December 21, 2021 - create_dockerfile: Create Dockerfile from Template · create_dockerignore: Create .dockerignore from template · docker: Use Docker · get_package_deps: Get R Package Dependencies · get_sysreqs: Get system requirements by R package · jimstemplates-package: jimstemplates: Collection of templates ·
Top answer
1 of 8
110

The .dockerignore file is similar to the .gitignore syntax. Here are some example rules:

# Ignore a file or directory in the context root named "modules"
modules

# Ignore any files or directories within the subdirectory named "modules" 
# in the context root
modules/*

# Ignore any files or directories in the context root beginning with "modules"
modules*

# Ignore any files or directories one level down from the context root named
# "modules"
*/modules

# Ignore any files or directories at any level, including the context root, 
# named modules
**/modules

# Ignore every file in the entire build context (see next rule for how this 
# could be used)
*

# Re-include the file or directory named "src" that may have been previously
# excluded. Note that you cannot re-include files in subdirectories that have 
# been previously excluded at a higher level
!src

Note that "build context" is the directory you pass at the end of your build command, typically a . to indicate the current directory. This directory is packaged from the docker client, excluding any files you have ignored with .dockerignore, and sent to the docker daemon to perform the build. Even when the daemon is on the same host as your client, the build only works from this context and not directly from the folders.

There is only a single .dockerignore for a build, and it must be in the root of the build context. It will not work if it is in your home directory (assuming you build from a subdirectory), and it will not work from a subdirectory of your build context.

To test what is in your current build context and verify your .dockerignore file is behaving correctly, you can copy/paste the following (this assumes you do not have an image named test-context, it will be overwritten and then deleted if you do):

# create an image that includes the entire build context
docker build -t test-context -f - . <<EOF
FROM busybox
COPY . /context
WORKDIR /context
CMD find .
EOF

# run the image which executes the find command
docker container run --rm test-context

# cleanup the built image
docker image rm test-context
2 of 8
57

.dockerignore is to prevent files from being added to the initial build context that is sent to the docker daemon when you do docker build, it doesn't create a global rule for excluding files from being created in all images generated by a Dockerfile.

It's important to note that each RUN statement will generate a new image, with the parent of that image being the image generated by the Dockerfile statement above it. Try collapsing your RUN statements into a single one to reduce image size:

RUN librarian-puppet install &&\
 puppet apply --modulepath=/modules -e "class { 'buildslave': jenkins_slave => true,}" &&\
 librarian-puppet clean
🌐
Medium
medium.com › @bounouh.fedi › mastering-the-dockerignore-file-boosting-docker-build-efficiency-398719f4a0e1
Mastering the .dockerignore File: Boosting Docker Build Efficiency | by Fedi Bounouh | Medium
November 9, 2024 - As you scale up your Docker projects, managing the build context efficiently becomes increasingly important. So next time you write a Dockerfile, make sure to add a .dockerignore file to the mix — it’s a small trick that can make a big difference!
🌐
TestDriven.io
testdriven.io › tips › 6850ab62-9323-4dca-8ddf-8db1d479accc
Tips and Tricks - Use a .dockerignore File | TestDriven.io
A properly structured .dockerignore file can help: Decrease the size of the Docker image · Speed up the build process · Prevent unnecessary cache invalidation · Prevent leaking secrets · Example: **/.git **/.gitignore **/.vscode **/coverage **/.env **/.aws **/.ssh Dockerfile README.md docker-compose.yml **/.DS_Store **/venv **/env ·
🌐
GitHub
github.com › moul › golang-repo-template › blob › main › .dockerignore
golang-repo-template/.dockerignore at main · moul/golang-repo-template
🌀 A template for creating new Golang + Docker + Canonical Domain + Badges + Dependabot + Renovate + GolangCI-lint + Goreleaser + GitHub Actions + Gitpod + Depaware + Git Hooks + ... - golang-repo-template/.dockerignore at main · moul/golang-repo-template
Author   moul
🌐
GitLab
gitlab.com › gitlab.org › repository
.dockerignore · master · GitLab.org / GitLab · GitLab
GitLab is an open source end-to-end software development platform with built-in version control, issue tracking, code review, CI/CD, and more. Self-host GitLab on your own servers, in a...
🌐
GitHub
github.com › Saluki › nestjs-template › blob › master › .dockerignore
nestjs-template/.dockerignore at master · Saluki/nestjs-template
Scaffold quickly your next TypeScript API with this opinionated NestJS template crafted for Docker environments - nestjs-template/.dockerignore at master · Saluki/nestjs-template
Author   Saluki