Sobes.tech
Junior — Middle

What instructions are typically used in a Dockerfile to build a project image?

sobes.tech AI

Answer from AI

The following instructions are typically used in a Dockerfile for building a Java project image:

  • FROM — base image, for example, openjdk:11-jre or maven:3.8.1-jdk-11 for building.
  • WORKDIR — setting the working directory inside the container.
  • COPY — copying source code and project files into the container.
  • RUN — executing commands, such as building the project with Maven or Gradle.
  • CMD or ENTRYPOINT — the command that runs the application when the container starts.

Example Dockerfile for a Java application:

FROM maven:3.8.1-jdk-11 AS build
WORKDIR /app
COPY pom.xml .
COPY src ./src
RUN mvn clean package -DskipTests

FROM openjdk:11-jre
WORKDIR /app
COPY --from=build /app/target/myapp.jar ./myapp.jar
CMD ["java", "-jar", "myapp.jar"]