Dockerfile
FROM maven:3.6.3-openjdk-11
# Set the working directory to the project root
WORKDIR /app
# Copy the pom.xml file to the image
COPY pom.xml .
# Build the project dependencies
RUN mvn dependency:go-offline
# Copy the rest of the project source code
COPY . /JAVA_AUTOMATION
# Build the project
RUN mvn package
# Set the default command to run when the container starts
CMD ["java", "-jar", "target/JAVA_AUTOMATION.jar"]
Docker Image build, Container run and Run Testcase
# Fetch the latest of running container
docker ps -l
# The docker rm command is used to remove the container. The $(...) syntax is used to execute the docker ps -l -q command and pass the output (which is the container ID of the latest container) as an argument to the docker rm command.
#This approach will delete the latest running container
docker rm $(docker ps -l -q)
#To remove a Docker image forcefully
docker rmi -f hn-automation
# Build the Docker image
docker build -t hn-automation .
# Run a new container based on the image, and Run test case command in container
docker run -it hn-automation mvn clean test -DsuiteXmlFile=testng.xml
Top comments (0)