Skip to content

Fix docker ignore#1273

Open
JaewonHur wants to merge 4 commits intoapple:mainfrom
JaewonHur:fix-docker-ignore
Open

Fix docker ignore#1273
JaewonHur wants to merge 4 commits intoapple:mainfrom
JaewonHur:fix-docker-ignore

Conversation

@JaewonHur
Copy link
Contributor

@JaewonHur JaewonHur commented Feb 26, 2026

This PR fixes container build to use docker specific ignore (#1169).
This PR relies on apple/container-builder-shim#68.

Given docker file path <dockerfile>, <dockerfile>.dockerignore should take precedence over .dockerignore file in context directory.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Motivation and Context

Docker specific ignore works.

Testing

  • Tested locally
  • Added/updated tests
  • Added/updated docs

@github-actions github-actions bot added the cli label Feb 26, 2026
@JaewonHur
Copy link
Contributor Author

╰─❯ TOOL=container ./test-ignore.sh
==========================================
Running .dockerignore tests with: container
==========================================

[TEST] Test 1: Basic .dockerignore
  $ ( cd test1-basic ; container build -t test-ignore:latest . )
[PASS] included.txt was copied (expected)
[PASS] ignored.txt was NOT copied (expected)

[TEST] Test 2: Dockerfile-specific ignore (Dockerfile.dockerignore)
  $ ( cd test2-specific ; container build -t test-ignore:latest . )
[PASS] specific.txt was NOT copied (correctly ignored by Dockerfile.dockerignore)
[PASS] general.txt was copied (only ignored by .dockerignore, not Dockerfile.dockerignore)

[TEST] Test 3: Containerfile with .containerignore
  $ ( cd test3-containerfile ; container build -f Containerfile -t test-ignore:latest . )
[PASS] included.txt was copied (expected)
[FAIL] ignored.txt was copied (unexpected)

[TEST] Test 4: Containerfile-specific ignore (Containerfile.containerignore)
  $ ( cd test4-containerfile-specific ; container build -f Containerfile -t test-ignore:latest . )
[FAIL] specific.txt was copied (should be ignored by Containerfile.containerignore)
[PASS] general.txt was copied (only ignored by .containerignore, not Containerfile.containerignore)

[TEST] Test 5: Build succeeds when Dockerfile is ignored
  $ ( cd test5-ignored-dockerfile ; container build -f Dockerfile -t test-ignore:latest . )
[PASS] Build succeeded even with Dockerfile in .dockerignore
[PASS] test.txt was copied (expected)

[TEST] Test 6: Build from subdirectory context
  $ ( cd test6-subdir ; container build -f subcontext/Dockerfile -t test-ignore:latest subcontext )
[PASS] included.txt was copied (expected)
[PASS] ignored.txt was NOT copied (expected)

[TEST] Test 7: No ignore file (all files should be copied)
  $ ( cd test7-no-ignore ; container build -t test-ignore:latest . )
[PASS] file1.txt was copied (expected)
[PASS] file2.txt was copied (expected)

[TEST] Test 8: Build with --platform and Dockerfile in subdirectory
  $ ( cd test8-platform-subdir-dockerfile ; container build --platform linux/amd64 -t test-ignore:latest -f nested/project/Dockerfile . )
[PASS] included.txt was copied (Dockerfile.dockerignore takes precedence over .dockerignore)
[PASS] secret.txt was NOT copied (correctly ignored by Dockerfile.dockerignore)
[PASS] nested/project/config.txt was copied (expected)

[TEST] Test 9: Custom-named Dockerfile (app1.Dockerfile)
  $ ( cd test9-custom-dockerfile-name ; container build -f app1.Dockerfile -t test-ignore:latest . )
[PASS] app1-specific.txt was NOT copied (correctly ignored by app1.Dockerfile.dockerignore)
[PASS] generic.txt was copied (only ignored by .dockerignore, not app1.Dockerfile.dockerignore)
[PASS] included.txt was copied (expected)

[TEST] Test 10: Custom-named Dockerfile in subdirectory
  $ ( cd test10-custom-name-subdir ; container build -f nested/project/app2.Dockerfile -t test-ignore:latest . )
[PASS] from-app2-ignore.txt was NOT copied (correctly ignored by app2.Dockerfile.dockerignore)
[PASS] from-root-ignore.txt was copied (only ignored by .dockerignore, not app2.Dockerfile.dockerignore)
[PASS] always-included.txt was copied (expected)
[PASS] nested/project/config.yaml was copied (expected)

[TEST] Test 11: app.Dockerfile with coexisting Dockerfile uses app.Dockerfile.dockerignore not Dockerfile.dockerignore
  $ ( cd test11-coexisting-dockerfiles ; container build -f app.Dockerfile -t test-ignore:latest . )
[PASS] app-specific.txt was NOT copied (correctly ignored by app.Dockerfile.dockerignore)
[PASS] dockerfile-specific.txt was copied (Dockerfile.dockerignore was not used)
[PASS] included.txt was copied (expected)

==========================================
Test Summary
==========================================
Passed: 25
Failed: 2
==========================================

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant