# dev_container: Resolve compose dockerfile path relative to build context \(\#53860\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/bc88fe49315352ebc362b0bc544fc69dd0784e39)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: bc88fe49315352ebc362b0bc544fc69dd0784e39

Requested commit: bc88fe49315352ebc362b0bc544fc69dd0784e39

Commit: bc88fe49315352ebc362b0bc544fc69dd0784e39

Tree: 130912904af44185fc8579323b459938dce99187

Author: Toni Alatalo

Committer: GitHub

## Message

```
dev_container: Resolve compose dockerfile path relative to build context (#53860)

## Context

When a Docker Compose service specifies `context: ..` and `dockerfile:
.devcontainer/Dockerfile`, Zed resolves the dockerfile path relative to
the compose file's directory instead of the build context. This produces
a doubled path like `.devcontainer/.devcontainer/Dockerfile` which
doesn't exist.

Per the [Docker Compose
spec](https://docs.docker.com/reference/compose-file/build/#dockerfile),
the `dockerfile` field is relative to the build context directory.

The fix resolves the context directory first (relative to the compose
file), then joins the dockerfile path to that.

Closes #53473

## Prior art

This fix is extracted from #53170 by @zdeneklapes, which addresses this
bug among several other dev container startup issues. This PR isolates
the dockerfile path resolution fix into a focused change to make it
easier to review and merge independently.

Differences from #53170:
- **Scope**: Only the dockerfile-relative-to-context fix, not the other
fixes (compose build args preservation, remote user fallback, Docker
inspect labels, etc.)
- **Implementation**: Inline resolution in `dockerfile_location()`
rather than separate helper methods
- **Absolute path handling**: Handles absolute dockerfile and context
paths
- **Tests**: Two test cases — compose file inside `.devcontainer/` with
`context: ..`, and compose file at project root with `context: .`

## How to Review

Single file change in
`crates/dev_container/src/devcontainer_manifest.rs`:
- **Fix** (line 234-252): Resolve build context relative to compose file
directory, then join dockerfile to that, instead of joining dockerfile
to `config_directory` directly. Uses `normalize_path` to resolve `..`
components.
- **Tests**: Two new `FakeDocker` compose config entries and
corresponding tests asserting correct resolved paths.

## Self-Review Checklist

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- Fixed docker-compose `dockerfile` path being resolved relative to the
compose file instead of the build `context` directory.

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
```

## Parents

- [e585523c8d4b71286b604a2f143eb1d812d9a12a](https://git.cafe/gitcafe/zed/commit/e585523c8d4b71286b604a2f143eb1d812d9a12a?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/bc88fe49315352ebc362b0bc544fc69dd0784e39?format=markdown)
