Run Maven Surefire Tests from Docker Container

Follow the below steps to build a docker image and run tests:

1. Create a Dockerfile in your project directory with below content.


FROM maven:3.5.3-jdk-8-alpine
COPY ./. /

2. Open a command prompt and navigate to your project directory.

3. Run the following docker command to build image from the Dockerfile.

C:\Projects\HelloWorldApplication>docker build --no-cache -t qascript:latest -f ./Dockerfile .

4. Run the following docker command to enter the container and open a terminal inside it.

docker run -it --rm qascript:latest /bin/sh

5. Run the maven command to run your tests inside the docker container.

mvn test



Bijan Patel

Founder & Creator of QAScript | 12+ years of IT Experience | Full Stack Automation Engineer | Blogger | Trainer

You may also like...

Leave a Reply

Your email address will not be published.