The error you're encountering indicates that the Docker image openjdk:23-jdk-alpine does not exist in the Docker Hub repository. Additionally, there's a deprecation warning about the legacy builder, suggesting you switch to using BuildKit. Below are the steps to resolve these issues:
1. Fixing the Base Image Error
Issue:
manifest for openjdk:23-jdk-alpine not found: manifest unknown: manifest unknown
Cause:
The openjdk:23-jdk-alpine tag does not exist in the official OpenJDK Docker repository. This could be due to:
- Non-existent Version: OpenJDK 23 may not have been released or the tag hasn't been published yet.
- Typographical Error: There might be a typo in the version number.
Solution:
-
Verify Available Tags:
Visit the OpenJDK Docker Hub page to see the available tags. As of now, commonly used tags include:
openjdk:17-jdk-alpine
openjdk:20-jdk-alpine
openjdk:21-jdk-alpine
-
Choose a Valid Tag:
Select a tag that suits your application's requirements. For example, if you want to use OpenJDK 20, update your Dockerfile as follows:
# Use an official OpenJDK runtime as a parent image
FROM openjdk:20-jdk-alpine
# Set environment variables (optional)
ENV SPRING_OUTPUT_ANSI_ENABLED=ALWAYS \
SPRING_JPA_SHOW_SQL=true \
JAVA_OPTS=""
# Set the working directory inside the container
WORKDIR /app
# Copy the executable JAR file to the container
COPY target/authentication_authorization-service-0.0.1-SNAPSHOT.jar app.jar
# Expose the port the application runs on
EXPOSE 8080
# Define the entry point to run the JAR
ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar app.jar"]
Alternatively, if you're flexible with the JDK variant, you can use a Slim image for a smaller footprint:
FROM openjdk:20-jdk-slim
-
Verify the Change:
After updating the Dockerfile, try building the Docker image again:
docker build -t your-image-name .
2. Addressing the Deprecation Warning
Warning:
DEPRECATED: The legacy builder is deprecated and will be removed in a future release.
Install the buildx component to build images with BuildKit:
https://docs.docker.com/go/buildx/
Cause:
Docker is moving away from the legacy builder in favor of BuildKit, which offers improved performance and new features.
Solution:
-
Enable BuildKit:
-
Temporarily (for a single build):
Prefix your docker build command with DOCKER_BUILDKIT=1:
DOCKER_BUILDKIT=1 docker build -t your-image-name .
-
Permanently:
Add the following to your Docker daemon configuration (~/.docker/config.json):
{
"features": {
"buildkit": true
}
}
Restart the Docker daemon after making this change.
-
Use docker buildx:
buildx is Docker's CLI plugin for BuildKit. It provides extended functionalities like multi-platform builds.
-
Initialize buildx:
docker buildx create --use
-
Build with buildx:
docker buildx build --tag your-image-name --platform linux/amd64,linux/arm64 .
For more detailed instructions, refer to the official Docker Buildx documentation.
Final Dockerfile Example:
Assuming you choose to use OpenJDK 20, your updated Dockerfile would look like this:
# Use an official OpenJDK runtime as a parent image
FROM openjdk:20-jdk-alpine
# Set environment variables (optional)
ENV SPRING_OUTPUT_ANSI_ENABLED=ALWAYS \
SPRING_JPA_SHOW_SQL=true \
JAVA_OPTS=""
# Set the working directory inside the container
WORKDIR /app
# Copy the executable JAR file to the container
COPY target/authentication_authorization-service-0.0.1-SNAPSHOT.jar app.jar
# Expose the port the application runs on
EXPOSE 8080
# Define the entry point to run the JAR
ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar app.jar"]
Additional Tips:
-
Check Image Availability:
Always verify the availability of a base image and its tags on Docker Hub before specifying it in your Dockerfile.
-
Use .dockerignore:
To reduce the build context size (currently 172.6MB), consider adding a .dockerignore file to exclude unnecessary files and directories from the build context. Example .dockerignore:
target/
.git
*.md
-
Keep Dependencies Updated:
Regularly update your base images to benefit from security patches and performance improvements.
If you follow these steps, your Docker build process should work correctly without encountering the manifest unknown error or the deprecation warning.
References:
Let me know if you need further assistance!