Docker构建镜像时curl下载ZIP包后unzip报invalid zip magic 0A0A0A0A错误
That invalid zip magic 0A0A0A0A error is a dead giveaway—you didn't actually download a valid ZIP file. The 0A is a newline character, which means your java-agent.zip is almost certainly an HTML error page from GitHub (like a 404, permission denied, or redirect response) instead of the actual agent archive.
Here's how to fix this step by step:
Add redirect following to your curl command
GitHub's download links often use 3xx redirects, and default curl behavior doesn't follow them. Add the-Lflag to make curl chase redirects, plus-oto ensure the output saves to the correct filename:curl -L -o java-agent.zip https://github.com/<your-repo-owner>/<your-repo>/releases/download/<release-tag>/java-agent.zipDouble-check your GitHub download URL
Make sure you're using the release asset URL, not the source code ZIP link. Source code links end with/archive/refs/tags/<tag>.zip—if you're after a pre-built agent, grab the link from the "Assets" section of the repo's release page instead.Handle private repo permissions
If the repo is private, curl will return an HTML login page instead of the ZIP. Add a GitHub personal access token (withreposcope) to your request:curl -L -H "Authorization: token YOUR_GITHUB_PAT" -o java-agent.zip https://github.com/<your-repo-owner>/<your-repo>/releases/download/<release-tag>/java-agent.zipPro tip: Don't hardcode tokens in your Dockerfile—use build args or secrets for better security.
Debug the downloaded file (optional but useful)
Add a quick step to inspect the file content before unzipping to confirm it's not HTML:RUN head java-agent.zipIf you see
<html>or<body>tags, you know your URL or permissions still need fixing.
Once you adjust the curl command to pull down a valid ZIP archive, that unzip error should vanish.
内容的提问来源于stack exchange,提问作者Siraj Syed

