> ## 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.

# hadolint/DL3045

> `COPY` to a relative destination without `WORKDIR` set.

`COPY` to a relative destination without `WORKDIR` set.

| Property | Value |
| - | - |
| Severity | Warning |
| Category | Best Practice |
| Default | Enabled |
| Auto-fix | Yes (suggestion `--fix-unsafe`; safe with `--slow-checks`) |

## Description

While copying to a relative path is not problematic per se, errors happen when changes are introduced to the `WORKDIR` without updating the
destination of the `COPY` command. It is assumed that when a `WORKDIR` is set, the programmer will make sure it works well together with the `COPY`
destinations.

## Examples

### Problematic code

```dockerfile theme={null}
FROM scratch
COPY foo bar
```

### Correct code

```dockerfile theme={null}
FROM scratch
COPY foo /bar
```

or:

```dockerfile theme={null}
FROM scratch
WORKDIR /
COPY foo bar
```

## Auto-fix

Inserts an explicit `WORKDIR` instruction before the first `COPY` with a relative destination.

* **Fast path** (no registry access): suggests `WORKDIR /app` as a conventional default (`FixSuggestion`, requires `--fix-unsafe`).
* **With `--slow-checks`**: resolves the base image's actual `WORKDIR` from the registry and uses that value (`FixSafe`, applied with `--fix`).

```dockerfile theme={null}
# Before
FROM python:3.12
COPY requirements.txt .

# After (with --fix-unsafe, fast path)
FROM python:3.12
WORKDIR /app
COPY requirements.txt .

# After (with --fix --slow-checks, base image has WORKDIR /usr/src/app)
FROM python:3.12
WORKDIR /usr/src/app
COPY requirements.txt .
```

## Reference

* [hadolint/DL3045](https://github.com/hadolint/hadolint/wiki/DL3045)


## Related topics

- [Hadolint rules](https://tally.wharflab.com/rules/hadolint/overview.md)
- [hadolint/DL3000](https://tally.wharflab.com/rules/hadolint/DL3000.md)
- [hadolint/DL3001](https://tally.wharflab.com/rules/hadolint/DL3001.md)
- [hadolint/DL3002](https://tally.wharflab.com/rules/hadolint/DL3002.md)
- [hadolint/DL3003](https://tally.wharflab.com/rules/hadolint/DL3003.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.