Home › Developer Tools › Dockerignore Generator

Dockerignore Generator

Pick your language, framework and extras to get a ready-to-use .dockerignore. A smaller build context means faster docker build runs, better layer caching and no secrets or node_modules copied into your image by accident.

Last updated:

1. Choose templates

Quick stacks:

2. Options

4. Your .dockerignore

Save the file as .dockerignore next to your Dockerfile, in the root of the build context (some browsers drop the leading dot when downloading, so rename it if needed). Unlike .gitignore, patterns are matched from the context root, so use **/ to match at any depth.

Advertisement
Advertisement

How to use the Dockerignore Generator

  1. Choose a quick stack such as Next.js or Django, or click individual templates for your language, framework and extras.
  2. Set the options: keep headers and comments for readability, or switch on allowlist mode for the tightest build context.
  3. Add custom entries for folders specific to your project, using ! to re-include a file.
  4. Check a path such as src/index.js or .env to confirm it is sent to the build or excluded.
  5. Copy or download the file and save it as .dockerignore next to your Dockerfile.

.dockerignore pattern rules

Docker reads the file line by line. Lines starting with # are comments, and the last pattern that matches a path decides whether it is excluded or included.

PatternWhat it matches
node_modulesOnly node_modules in the context root, and everything inside it
**/node_modulesnode_modules at any depth, such as packages/web/node_modules
*.logLog files in the root only; use **/*.log for every folder
docs/*.mdMarkdown files directly in docs, not in its subfolders
temp?temp1, tempA: ? is exactly one character other than /
*.py[cod].pyc, .pyo and .pyd files in the root
!README.mdRe-includes a file excluded by an earlier pattern
* then !srcAllowlist: everything is excluded except the src folder

Why a small build context matters

  • Speed: the whole context is transferred to the builder before the first instruction runs. A forgotten node_modules or .git folder can add hundreds of megabytes to every build.
  • Caching: COPY . . is rebuilt whenever any file in the context changes. Excluding logs, caches and editor files keeps that layer cached while you work.
  • Correctness: dependencies installed on your laptop may be built for a different operating system or CPU. Ignoring node_modules, .venv or target forces a clean install inside the image.
  • Security: .env files, SSH keys and cloud credentials in the context can end up in a layer that anyone with pull access can read.

Tips

  • Look for the "transferring context" size in the docker build output before and after adding the file to see how much it saves.
  • If a build fails with "file not found" after adding a .dockerignore, check the path with the checker above: a broad pattern such as build or **/*.md may exclude a file your Dockerfile copies.
  • Exclude Tests only if your Dockerfile does not run the test suite during the build.
  • Pair this file with a .gitignore for the repository, and review the Dockerfile itself with the Dockerfile Linter.

Frequently asked questions

What does a .dockerignore file do?

When you run docker build, the CLI sends the build context (usually the current folder) to the builder. Files matched by .dockerignore are left out of that context, so they cannot be copied into the image with COPY or ADD, the upload is smaller, and changes to ignored files do not invalidate the build cache.

How is .dockerignore different from .gitignore?

The syntax looks similar but matching differs. In .dockerignore every pattern is relative to the root of the build context, so node_modules only matches the top-level folder; use **/node_modules to match it at any depth. A trailing slash has no special meaning, and ! exceptions can re-include files inside an excluded folder, which .gitignore does not allow.

Should I ignore the Dockerfile and .dockerignore themselves?

You can. Docker still sends both files to the builder because it needs them, but they will not be copied into the image by COPY . . and editing them will not bust the cache of a COPY . . layer. The Docker files template does exactly this.

What is allowlist mode?

Instead of listing everything to exclude, the file starts with * to ignore the whole context and then re-includes only the paths the build needs, such as !package.json and !src. It produces the smallest possible context and prevents surprises when new files appear, but you must remember to add new folders the build uses.

Why should .env files and keys be ignored?

Anything in the build context can end up in an image layer through COPY . ., and image layers are easy to extract by anyone who can pull the image. Ignoring .env files, private keys and cloud credentials keeps them out; pass secrets at runtime or with BuildKit secret mounts instead.

Where do I put the .dockerignore file?

In the root of the build context, which is the folder you pass to docker build (the . in docker build .). With BuildKit you can also place a Dockerfile-specific file next to the Dockerfile, named after it, for example app.Dockerfile.dockerignore.

Does the path checker match Docker exactly?

It follows the documented rules: patterns are anchored at the context root, * and ? do not cross folder separators, ** matches any number of folders, a pattern that matches a folder excludes everything inside it, and the last matching line wins. Unusual edge cases can still differ, so verify critical paths with a test build.

Are all the tools on FreeToolCabin tested for quality and accuracy?

Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

Related tools

Dockerfile GeneratorGenerate a production Dockerfile and .dockerignore for Node, Python, Go or a static nginx site.Dockerfile LinterLint a Dockerfile for best practices: pinned tags, apt cleanup, non-root USER and layer count.Gitignore GeneratorBuild a .gitignore from 50+ templates for languages, frameworks, IDEs and OS, merged and deduped.Docker Compose ValidatorCheck a docker-compose.yml for YAML errors, schema mistakes, broken references and deprecated keys.QR Code GeneratorMake QR codes for links, Wi-Fi, email and more.Barcode GeneratorCreate Code 128, EAN-13, UPC-A, EAN-8, Code 39 and ITF-14 barcodes as PNG or SVG.UUID GeneratorGenerate UUID v4 and v7 / GUIDs in bulk and copy or download them.Schema Markup Generator (JSON-LD)Create JSON-LD structured data for FAQ, Product, Article and more.Htaccess & Nginx Redirect GeneratorBuild 301 redirects for .htaccess, Nginx and Netlify or Cloudflare _redirects.Fake Data GeneratorGenerate mock data as JSON, CSV or SQL.Random String GeneratorGenerate secure random strings and tokens in bulk with any length and character set.API Key GeneratorCreate secure API keys and secrets with prefixes, checksums and SHA-256 hashes for storage.MIME Type LookupFind the MIME type for any file extension, or the extensions for a MIME type, in 400+ entries.Cron Expression GeneratorBuild crontab schedules visually, read them in plain English and see the next run times.URL Slug GeneratorTurn titles into clean, SEO-friendly URL slugs: accents, stop words, separators and bulk lines.JSON Schema GeneratorTurn sample JSON into a draft 2020-12 JSON Schema with types, required fields and formats.License GeneratorCreate a LICENSE file for MIT, Apache, GPL, BSD, ISC, MPL or Unlicense with your name and year.ULID GeneratorGenerate sortable ULIDs and UUID v7 in bulk, monotonic option, and decode their timestamps.Htpasswd GeneratorCreate .htpasswd entries with bcrypt, APR1-MD5 or SHA-1 for Apache and Nginx basic auth.Placeholder Image GeneratorCreate placeholder images in any size, color and text as PNG, JPG, WebP, SVG or data URI.Ads.txt GeneratorCreate or validate ads.txt and app-ads.txt files: seller lines, cert IDs and variables.Docker Run to Compose ConverterConvert docker run commands to docker-compose.yml, or a compose file back to docker run.HTML Boilerplate GeneratorTick the options you need and get a clean HTML5 starter template with meta, OG tags and CSS reset.JSON to Zod SchemaInfer a Zod (or Yup) schema from sample JSON with optional, nullable and z.infer types.Linux Commands Cheat SheetSearchable Linux and bash command reference with flags explained, examples and copy buttons.LLMs.txt GeneratorBuild an llms.txt file for AI crawlers: summary and link sections, import from your sitemap.Nano ID GeneratorGenerate secure Nano IDs with custom alphabet, length and count, plus a collision calculator.Nginx Config GeneratorBuild an nginx server block: static site, SPA, reverse proxy or PHP, with SSL, gzip and redirects.OpenAPI / Swagger ViewerView OpenAPI 2/3 JSON or YAML as interactive API docs with validation and an endpoint list.package.json GeneratorFill a form and get a valid, npm-ready package.json with scripts, dependencies and checks.PKCE Code Challenge GeneratorGenerate an OAuth 2.0 PKCE code_verifier and S256 code_challenge, build auth URLs, verify pairs.README GeneratorFill in a form and get a polished README.md with badges, install, usage and license, live preview.Regex GeneratorBuild regular expressions visually from blocks or presets (email, date, phone) and test them live.Commit Message GeneratorBuild Conventional Commit messages with type, scope, body, breaking change and issue refs.Database Schema DesignerDesign tables and relationships visually, then export SQL for MySQL, PostgreSQL or SQLite.Docker Compose GeneratorBuild a docker-compose.yml with a form: services, ports, volumes, env, healthchecks and presets.Dummy File GeneratorCreate test files of an exact size in KB, MB or GB with zeros, random bytes or text.FFmpeg Command GeneratorPick a task and options, get the exact ffmpeg command with every flag explained.Truth Table GeneratorType a logic expression and get its full truth table, minterms and canonical DNF/CNF.TypeScript PlaygroundWrite TypeScript with live type checking, see the compiled JavaScript and run it in your browser.Article Schema GeneratorCreate Article, BlogPosting or NewsArticle JSON-LD with headline, authors, dates and images.Event Schema GeneratorCreate Event JSON-LD with dates, venue or online location, tickets, organizer and performers.Google Search Query BuilderBuild advanced Google searches with site:, filetype:, intitle:, exact phrases and date operators.HowTo Schema GeneratorCreate HowTo JSON-LD with steps, tools, supplies, total time and cost, then copy it.Htaccess GeneratorBuild an Apache .htaccess file: HTTPS, www, gzip, caching, error pages, IP blocks, hotlinks.HTML Email Template BuilderDrag and drop blocks to build a responsive, table-based HTML email with inline styles.Organization Schema GeneratorCreate Organization JSON-LD with logo, URL, contact points, address and social profiles.PIN GeneratorGenerate random 4, 6 or 8-digit PINs that avoid sequences, repeats, dates and common PINs.Product Schema GeneratorBuild Product JSON-LD with price, availability, brand, GTIN, ratings and reviews.Question Keyword GeneratorFind the questions people ask about a topic, grouped by who, what, why, how, can and more.Recipe Schema GeneratorCreate Recipe JSON-LD with ingredients, steps, prep and cook times, nutrition and ratings.Security Headers GeneratorPick HSTS, CSP, frame, referrer and permissions options and get Apache, Nginx, Netlify or Cloudflare config.SKU GeneratorBuild consistent SKUs from brand, category, size and color, then export every variant as CSV.Typography Scale GeneratorBuild a modular type scale from a base size and ratio, then copy CSS variables or a Tailwind config.WordPress Salt GeneratorGenerate fresh WordPress security keys and salts for wp-config.php, .env or Docker in one click.ANSI Color Code GeneratorStyle terminal text with 16, 256 or RGB colors and get escape codes for bash, Python, JS and C.Apache Virtual Host GeneratorCreate an Apache VirtualHost config with SSL, redirects, reverse proxy or PHP-FPM in seconds.Bash Prompt GeneratorDrag and drop a custom PS1 prompt for bash or zsh with colors, git branch and a live preview.Changelog GeneratorTurn Conventional Commit messages into a grouped Keep a Changelog Markdown file per version.cURL Command BuilderBuild curl commands from a form: method, headers, query, JSON or form body, auth and flags.Docker Compose to KubernetesConvert docker-compose.yml into Kubernetes Deployment, Service, ConfigMap and PVC manifests.ESLint Config GeneratorGenerate a flat eslint.config.js for JavaScript, TypeScript, React or Node with rule presets.Git Branch Name GeneratorTurn a ticket ID and title into a clean, valid git branch name like feature/PROJ-12-add-login.GitLab CI Config GeneratorGenerate a .gitlab-ci.yml with stages, jobs, images, cache, artifacts and rules from templates.Jinja2 Template TesterRender Jinja2 templates with YAML or JSON variables using real Jinja2, with clear error lines.JSON Schema Mock Data GeneratorGenerate realistic sample JSON from a JSON Schema: formats, patterns, $ref, seeds and counts.Kubernetes Secret GeneratorCreate Kubernetes Secret YAML from key/value pairs or .env with auto base64, or decode one.Kubernetes YAML ValidatorValidate Kubernetes manifests against the API schema of a chosen version, with error paths.
See all 85 Code Generators & Builders →