> ## Documentation Index
> Fetch the complete documentation index at: https://tally.wharflab.com/llms.txt
> Use this file to discover all available pages before exploring further.

# buildkit/CopyIgnoredFile

> Attempting to Copy file that is excluded by .dockerignore.

Attempting to Copy file that is excluded by .dockerignore.

| Property | Value       |
| -------- | ----------- |
| Severity | Warning     |
| Category | Correctness |
| Default  | Enabled     |

## Description

When you use the `ADD` or `COPY` instructions in a Dockerfile, you should
ensure that the files to be copied into the image do not match a pattern present
in `.dockerignore`. Files which match the patterns in a `.dockerignore` file are
not present in the context of the image when it is built. Trying to copy or add
a file which is missing from the context will result in a build error.

## Build context requirement

This rule needs build context information. In direct Dockerfile mode, pass a local context directory:

```bash theme={null}
tally lint --context . Dockerfile
```

When linting a Bake or Compose entrypoint, tally uses the local `context` declared by the selected target or service:

```bash theme={null}
tally lint docker-bake.hcl --target api
tally lint compose.yaml --service api
```

Remote, tar, git, and empty contexts are valid build declarations, but tally does not fetch or unpack them during linting. For those contexts, this
rule only reports problems that can be determined without reading context files.

## Examples

Given a `.dockerignore` containing `*/tmp/*`:

Bad:

```dockerfile theme={null}
FROM scratch
COPY ./tmp/helloworld.txt /helloworld.txt
```

Good:

```dockerfile theme={null}
FROM scratch
COPY ./forever/helloworld.txt /helloworld.txt
```

## Reference

* [buildkit/CopyIgnoredFile](https://docs.docker.com/reference/build-checks/copy-ignored-file/)
