Skip to content

[Bug]: Dockerignore Resolution Order Differs from Docker Proper #1800

Description

@KazWolfe

I have done the following

  • 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
  1. Create a .dockerignore:
/foo/*
!/foo/.gitkeep

/foo/bar/*
!/foo/bar/.gitkeep
  1. Create a Dockerfile:
FROM scratch
COPY . .
  1. 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 .keeps.

Environment

- 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

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions