---
title: "Send only the files the build needs · Agent Wranglers"
url: https://agentwranglers.se/playbook/engineering/build-test-and-deploy/dockerignore
id: ENG-66
level: Recommended
applies: servers
updated: 2026-10-27
build: a2a6bdfed830
tokens: 722
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Send only the files the build needs

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Build, test and deploy](https://agentwranglers.se/playbook/engineering/build-test-and-deploy.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers.md). Updated 2026-10-27.

- ID: ENG-66
- Level: Recommended
- Chapter: [Build, test and deploy](https://agentwranglers.se/playbook/engineering/build-test-and-deploy.md)
- Rule: Keep a `.dockerignore` that leaves out dependencies, build output, version control, local data and every secret file.
- Check: Build with a test file named `.env.leak-test` in the folder. Then `docker run --rm --entrypoint sh shop -c 'find / -name ".env*" -not -path "/proc/*"'` prints nothing.
- Applies when: The project runs its own servers, virtual machines or containers.
- How: The build sends the whole folder to the builder unless you exclude files. Without the list, a local `.env` or a stray key can land in an image layer. List `node_modules`, `dist`, `.git`, data folders, `.env*` and key files. It backs up [Keep secrets out of code](https://agentwranglers.se/playbook/application-security/secrets-and-configuration/secrets-out-of-code.md).

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### Plain text example

```text
**/node_modules
**/dist
.git
**/data
**/.env*
**/*.pem
```

## Sources

- [Docker build context and .dockerignore](https://docs.docker.com/build/concepts/context/)
- [NIST SP 800-190 Application Container Security Guide](https://csrc.nist.gov/pubs/sp/800/190/final)

## Related rules

- APS-60 [Keep secrets out of code](https://agentwranglers.se/playbook/application-security/secrets-and-configuration/secrets-out-of-code.md) in Application security
- APS-65 [Serve no hidden files](https://agentwranglers.se/playbook/application-security/secrets-and-configuration/no-hidden-files.md) in Application security

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/engineering/build-test-and-deploy/dockerignore">Agent Wranglers engineering playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Keep build tools out of the runtime image](https://agentwranglers.se/playbook/engineering/build-test-and-deploy/multi-stage-builds.md)
- Next: [Run the same images locally with Compose](https://agentwranglers.se/playbook/engineering/build-test-and-deploy/compose-for-local.md)
- [Build, test and deploy](https://agentwranglers.se/playbook/engineering/build-test-and-deploy.md)
