Docker COPY --from stage not found in CI
A docker COPY --from stage not found does not produce a message about stages, because BuildKit does not treat an unknown name as a mistake. It treats it as an image reference and goes to a registry for it, so the line in your log is an authorization failure for a repository you have never heard of. A numeric index behaves completely differently and does say what is wrong. A name that matches no…
When a Docker COPY --from stage cannot be found in the CI pipeline, it does not generate an error message about stages. This is because BuildKit, the underlying technology, treats an unknown name as an image reference and searches for it in a registry instead of treating it as a mistake. The log entry in this case indicates an authorization failure for a repository that has never been seen before. In contrast, a numeric index behaves differently and explicitly points out the issue.
The error message "pull access denied, repository does not exist or may require authorization" suggests that the stage name is misspelled or has been renamed elsewhere in the Dockerfile. This scenario often goes unnoticed during code reviews, as the diff appears to be a simple rename and the missing `COPY --from` reference is located elsewhere in the file.
Another common cause is copying from a stage that exists in a different Dockerfile, which can happen when a team splits one Dockerfile into multiple files or copies a stanza between services.
If the stage name is numeric and falls outside the valid range, the error message will be "invalid stage index N." This issue usually arises when stages are inserted or removed from the file, causing the index to become out of range. It is important to note that an unmatched name is treated as an image reference, and stage names that resemble image names may result in a silent registry trip rather than an error.
To resolve the issue, it is recommended to read the last words of the line first. If the message ends with a suggestion naming one of your stages, correct the spelling and stop reading the registry text. If there is no suggestion, manually compare the name with the `FROM ... AS` lines in the Dockerfile, as typos may be too large to be suggested. After addressing the typo, verify whether the issue has been resolved or if it is a real pull problem requiring attention to credentials.
In order to prevent such errors from occurring, it is advised to give every stage an explicit name and never reference a stage using an index. Prefixing stage names can also help prevent confusion, as an unmatched name would not be mistaken for an image reference in the log. Additionally, it is crucial to keep credentials present in jobs that build, as a registry denial will always be related to the stage name rather than authentication issues.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.