Skip to content

Report an unreadable build context as permission denied, not a missing Dockerfile - #2093

Open
devops-thiago wants to merge 1 commit into
apple:mainfrom
devops-thiago:build-context-unreadable-error
Open

devops-thiago wants to merge 1 commit into
apple:mainfrom
devops-thiago:build-context-unreadable-error

Conversation

@devops-thiago

@devops-thiago devops-thiago commented Aug 7, 2026 •

Copy link
Copy Markdown

Type of Change

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

Motivation and Context

Fixes #2089.

FileManager.fileExists is false both for a path that is not there and for one the process may not look at, and the build options reported "not found" for both. On the 1.5.0 release:

mkdir ctx && printf 'FROM alpine\n' > ctx/Dockerfile && chmod 000 ctx
container build ctx
Error: dockerfile not found in context dir
container build -f ctx/Dockerfile ctx
Error: dockerfile does not exist ctx/Dockerfile

Both messages send the user to inspect a Dockerfile that is there. The same conflation is still on main, with a new wording for --file (file does not exist ctx/Dockerfile, from BuildOptions.validate()) and the old one for the default lookup (dockerfile not found in context dir, from resolveDockerfile()).

When the lookup fails, the code now checks stat's errno. EACCES or EPERM reports cannot read context dir <path>: permission denied for the default lookup, or cannot read file <path>: permission denied for --file. A directory that simply holds no Dockerfile keeps dockerfile not found in context dir, and a missing --file keeps file does not exist.

The first version of this change was in BuildCommand. #2298 moved the build command into a plugin, so I ported the change to BuildOptions and force-pushed the branch.

Testing

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

BuildOptionsTests parses the options against temporary contexts and calls resolveDockerfile(): unreadable, unreadable with --file, readable without a Dockerfile, a missing --file, and a readable context with a Dockerfile. On current main the two unreadable cases fail because the message has no permission denied, and the other three pass. With this change all five pass, and so does the full unit suite. The two permission tests skip themselves when run as root.

--file is checked while the arguments are validated, so it needs no daemon. I ran it from debug builds of container-build, one at main (b3eb7030) and one with this change:

$ chmod 000 ctx
$ container-build -f ctx/Dockerfile ctx      # main
Error: file does not exist ctx/Dockerfile
$ container-build -f ctx/Dockerfile ctx      # this branch
Error: cannot read file ctx/Dockerfile: permission denied

The default lookup runs after the plugin's daemon health check, so I covered it with the unit test and did not run it end to end.

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Code Coverage

Tier Line Coverage
Unit 22.52%
Integration 69.38%
Combined 77.51%

@devops-thiago

Copy link
Copy Markdown
Author

@dkovba thank you for approving the workflows. CI passes on this PR and it still merges cleanly into main. Is it good to merge as it is, or is there anything else you need from me?

…erfile

FileManager.fileExists is false both for a path that is not there and for
one the process may not look at. A build whose context directory was
unreadable therefore reported "dockerfile not found in context dir", and
with --file "file does not exist". Both sent people looking for a
Dockerfile that was there.

When the lookup fails, check stat's errno. EACCES or EPERM now reports
"cannot read context dir <path>: permission denied" or "cannot read file
<path>: permission denied". A directory that simply holds no Dockerfile
keeps the old messages.
@devops-thiago
devops-thiago force-pushed the build-context-unreadable-error branch from 3d62a6b to fd428d9 Compare October 14, 2026 21:01
@devops-thiago

Copy link
Copy Markdown
Author

@dkovba #2298 moved the build command into a plugin, so this no longer applied. I ported the change to BuildOptions and updated the description. The runs need approval again, thank you.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: container build reports "dockerfile not found in context dir" when the context is unreadable

1 participant