apple / apple/container

[Bug]: Dockerignore Resolution Order Differs from Docker Proper

Open
#1,800 6 comments 3 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
49.9k
Forks
1.8k
Avg merge
1d 20h
Merged PRs (30d)
22

Description

### I have done the following

- [x] I have searched the existing issues
- [ ] If possible, I've reproduced the issue using the 'main' branch of this project

### Steps to reproduce

1. Create a new directory somewhere.
2. Create some dummy files:
```
mkdir -p foo/bar
touch foo/.gitkeep foo/bar/.gitkeep
```
3. Create a `.dockerignore`:
```
/foo/*
!/foo/.gitkeep

/foo/bar/*
!/foo/bar/.gitkeep
```
4. Create a `Dockerfile`:
```
FROM scratch
COPY . .
```
5. Attempt a build with `container build`.

### Problem description

`.dockerignore` resolution differs slightly between Docker standard and `container build`, especially when resolving (un)ignored paths. The provided sample files emit the following error upon building:

```
container build
[+] Building 0.1s (3/4)
=> [internal] load build definition from Dockerfile
=> => transferring dockerfile: 58B
=> [internal] load .dockerignore
=> => transferring context: 91
=> ERROR [internal] load build context
=> => transferring context: 142B
------
> [internal] load build context:
------
Error: unknown: "failed to solve: changes out of order: "foo/bar/.gitkeep" "foo/.gitkeep""
```

This causes problems with, e.g., the default Rails .dockerignore configuration as generated by `rails new` and it leverages this layering to include/exclude certain subpaths while preserving `.keep`s.

### Environment

```markdown
- OS: macOS 26.5.1 (25F80)
- Xcode: 26.5 (17F42)
- Container: CLI version 1.0.0 (build: release, commit: unspeci); installed via Brew
```

### Code of Conduct

- [x] I agree to follow this project's Code of Conduct

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the report with the shown .dockerignore, Dockerfile, and `container build` command, then trace the build-context handling for ignored and re-included paths. Done means the nested `.gitkeep` files are processed in Docker-compatible resolution order and the build no longer reports changes out of order.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, swift
Domain
build-system, cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
66/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.