How to build a docker image for a Java application using Amazon Corretto 25 JDK
- Create a Dockerfile: This file contains instructions on how to build the Docker image. Here is a simple example:
FROM amazoncorretto:25-jdk
WORKDIR /app
COPY target/docker-java-0.0.1-SNAPSHOT.jar app.jar
CMD ["java", "-jar", "app.jar"]
EXPOSE 8080
- Build the Docker Image: Use the
docker build command to create the image. Run this command in the directory where your Dockerfile is located:
docker build -t your-image-name .
- Run the Docker Container: Once the image is built, you can run it using the
docker run command:
docker run -p 8080:8080 your-image-name