Docker构建报错:拉取opejdk镜像权限被拒,求解决方案
Hey there, let's work through this issue together! The error you're seeing has two clear causes, and fixing them will get your build up and running smoothly.
1. Typo in Docker Image Name
The immediate error stems from a simple typo: you wrote opejdk:11.0.7-jre instead of openjdk:11.0.7-jre. Docker Hub doesn't host an official image named opejdk, so it can't pull the resource you're requesting, hence the "pull access denied" message.
2. Missing Builder Stage Alias
Your Dockerfile uses multi-stage builds, but you didn't label the first build stage with an alias (like builder). When you try to run COPY --from=builder, Docker has no way to identify which stage to copy files from.
Corrected Dockerfile
Here's the fixed version of your Dockerfile with both issues addressed:
# First build stage - labeled as "builder" for later reference FROM openjdk:11.0.7-jdk AS builder RUN apt-get install -y unzip ENV APP_HOME=/root/dev/beverage WORKDIR $APP_HOME COPY . $APP_HOME WORKDIR /app RUN curl -L https://services.gradle.org/distributions/gradle-6.5.1-bin.zip -o gradle-6.5.1-bin.zip RUN unzip gradle-6.5.1-bin.zip ENV GRADLE_HOME=/app/gradle-6.5.1 ENV PATH=$PATH:$GRADLE_HOME/bin WORKDIR $APP_HOME RUN gradle build # Second runtime stage - corrected image name FROM openjdk:11.0.7-jre WORKDIR /root/ # Now we can correctly reference the "builder" stage to copy the built jar COPY --from=builder /root/dev/beverage/build/libs/bev-all.jar . CMD ["java", "-jar", "bev-all.jar"]
Key Changes Explained
- Added
AS builderto the firstFROMline: This marks the initial build stage, making it accessible via thebuilderalias in subsequent stages. - Fixed
opejdktoopenjdkin the secondFROMline: Docker can now pull the official, supported OpenJRE image from Docker Hub.
Once you update your Dockerfile with these tweaks, re-run docker build -t beverage . and it should complete successfully!
内容的提问来源于stack exchange,提问作者Ahmed Ali

