how to create and run docker image using Maven from dockerfile Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!IntelliJ inspection gives “Cannot resolve symbol” but still compiles codeHow is Docker different from a virtual machine?Should I use Vagrant or Docker for creating an isolated environment?How to list containers in DockerHow to get a Docker container's IP address from the host?How to remove old Docker containersHow does one remove an image in Docker?Copying files from Docker container to hostCopying files from host to Docker containerHow to copy Docker images from one host to another without using a repository
My bank got bought out, am I now going to have to start filing tax returns in a different state?
My admission is revoked after accepting the admission offer
Is Bran literally the world's memory?
Why did Israel vote against lifting the American embargo on Cuba?
Married in secret, can marital status in passport be changed at a later date?
Where did Arya get these scars?
Co-worker works way more than he should
Passing args from the bash script to the function in the script
Function to calculate red-edgeNDVI in Google Earth Engine
Does the set of sets which are elements of every set exist?
What was Apollo 13's "Little Jolt" after MECO?
How to translate "red flag" into Spanish?
Justification for leaving new position after a short time
Does Feeblemind produce an ongoing magical effect that can be dispelled?
What's parked in Mil Moscow helicopter plant?
std::is_constructible on incomplete types
Why did C use the -> operator instead of reusing the . operator?
Expansion//Explosion and Siren Stormtamer
Is a 5 watt UHF/VHF handheld considered QRP?
Error: Syntax error. Missing ')' for CASE Statement
Password Generator in batch
Need of separate security plugins for both root and subfolder sites Wordpress?
Mistake in years of experience in resume?
Implementing 3DES algorithm in Java: is my code secure?
how to create and run docker image using Maven from dockerfile
Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!IntelliJ inspection gives “Cannot resolve symbol” but still compiles codeHow is Docker different from a virtual machine?Should I use Vagrant or Docker for creating an isolated environment?How to list containers in DockerHow to get a Docker container's IP address from the host?How to remove old Docker containersHow does one remove an image in Docker?Copying files from Docker container to hostCopying files from host to Docker containerHow to copy Docker images from one host to another without using a repository
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am new to docker , we are trying to create docker image for my project which we used run in simple Maven commands
mvn verify
a quick google search gives me - Dockerfile
FROM maven:3.6.0-jdk-8
COPY src C:/docker/
COPY pom.xml C:/docker/
COPY testng.xml C:/docker/
RUN mvn -f C:docker clean verify
my understanding from above commands are , fetch maven 3.6 image from docker hub and copy existing project files to docker container and run the maven commands .
My POM.XML looks like
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-testng</artifactId>
<version>1.2.5</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.44.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.26</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>3.8.0</version>
<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>sample</projectName>
<outputDirectory>target/cucumber-reports/advanced-reports</outputDirectory>
<cucumberOutput>target/cucumber-reports/CucumberTestReport.json</cucumberOutput>
<buildNumber>1</buildNumber>
<parallelTesting>false</parallelTesting>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
I am getting an error saying
POM file C:docker specified with the -f/--file command line argument
does not exist
I know that , i have problem with my docker basics , but it would be great help if you teach/tell me what could be the issue here .
maven docker
add a comment |
I am new to docker , we are trying to create docker image for my project which we used run in simple Maven commands
mvn verify
a quick google search gives me - Dockerfile
FROM maven:3.6.0-jdk-8
COPY src C:/docker/
COPY pom.xml C:/docker/
COPY testng.xml C:/docker/
RUN mvn -f C:docker clean verify
my understanding from above commands are , fetch maven 3.6 image from docker hub and copy existing project files to docker container and run the maven commands .
My POM.XML looks like
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-testng</artifactId>
<version>1.2.5</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.44.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.26</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>3.8.0</version>
<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>sample</projectName>
<outputDirectory>target/cucumber-reports/advanced-reports</outputDirectory>
<cucumberOutput>target/cucumber-reports/CucumberTestReport.json</cucumberOutput>
<buildNumber>1</buildNumber>
<parallelTesting>false</parallelTesting>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
I am getting an error saying
POM file C:docker specified with the -f/--file command line argument
does not exist
I know that , i have problem with my docker basics , but it would be great help if you teach/tell me what could be the issue here .
maven docker
add a comment |
I am new to docker , we are trying to create docker image for my project which we used run in simple Maven commands
mvn verify
a quick google search gives me - Dockerfile
FROM maven:3.6.0-jdk-8
COPY src C:/docker/
COPY pom.xml C:/docker/
COPY testng.xml C:/docker/
RUN mvn -f C:docker clean verify
my understanding from above commands are , fetch maven 3.6 image from docker hub and copy existing project files to docker container and run the maven commands .
My POM.XML looks like
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-testng</artifactId>
<version>1.2.5</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.44.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.26</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>3.8.0</version>
<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>sample</projectName>
<outputDirectory>target/cucumber-reports/advanced-reports</outputDirectory>
<cucumberOutput>target/cucumber-reports/CucumberTestReport.json</cucumberOutput>
<buildNumber>1</buildNumber>
<parallelTesting>false</parallelTesting>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
I am getting an error saying
POM file C:docker specified with the -f/--file command line argument
does not exist
I know that , i have problem with my docker basics , but it would be great help if you teach/tell me what could be the issue here .
maven docker
I am new to docker , we are trying to create docker image for my project which we used run in simple Maven commands
mvn verify
a quick google search gives me - Dockerfile
FROM maven:3.6.0-jdk-8
COPY src C:/docker/
COPY pom.xml C:/docker/
COPY testng.xml C:/docker/
RUN mvn -f C:docker clean verify
my understanding from above commands are , fetch maven 3.6 image from docker hub and copy existing project files to docker container and run the maven commands .
My POM.XML looks like
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-testng</artifactId>
<version>1.2.5</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.44.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.26</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>3.8.0</version>
<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>sample</projectName>
<outputDirectory>target/cucumber-reports/advanced-reports</outputDirectory>
<cucumberOutput>target/cucumber-reports/CucumberTestReport.json</cucumberOutput>
<buildNumber>1</buildNumber>
<parallelTesting>false</parallelTesting>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
I am getting an error saying
POM file C:docker specified with the -f/--file command line argument
does not exist
I know that , i have problem with my docker basics , but it would be great help if you teach/tell me what could be the issue here .
maven docker
maven docker
asked Mar 22 at 15:56
user1553680user1553680
6219
6219
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
C:/docker/
is not a valid path in maven:3.6.0-jdk-8
image, you should have used something like /docker/
instead.
The following Dockerfile
:
FROM maven:3.6.0-jdk-8
COPY pom.xml /docker/
COPY testng.xml /docker/
COPY src /docker/
RUN cd /docker/ && mvn clean verify
should work and run mvn clean verify
in a Docker container. You could also set the working directory to avoid repeating /docker/
everywhere :
FROM maven:3.6.0-jdk-8
RUN mkdir /docker
WORKDIR /docker
COPY pom.xml .
COPY testng.xml .
COPY src .
RUN mvn clean verify
Finally, a little trick when building with Maven like you do (outside the scope of your question but good to know) : you can significantly reduce the time of your build by downloading dependencies (using mvn dependency:resolve
) just after the COPY pom.xml /docker/
directive, like :
FROM maven:3.6.0-jdk-8
RUN mkdir /docker
WORKDIR /docker
COPY pom.xml .
RUN mvn dependency:resolve
COPY testng.xml .
COPY src .
RUN mvn clean verify
By doing so, if you build your image twice, but just updating files in src
folder the 2nd time, Docker will be able to use the cached layer and restart from COPY src .
layer (therefore not re-downloading all dependencies). But of course, if you update your pom.xml
, Docker will re-download all dependencies during the next build.
I have modified the Dockerfile as per your suggestion and try to build the image usingdocker build -t sample .
. but i got the error saying "There was an error in Forked Process , Cannot find class in classpath: TestRunner , org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process ". Please let me know if you can help me .
– user1553680
Mar 25 at 0:53
This error is related to Maven, do you have the same error when building locally (not inside the container)?
– norbjd
Mar 25 at 9:56
nope . It worked fine .
– user1553680
Mar 25 at 13:31
It should be related to your tests configuration (maven-surefire-plugin
,JUnit
ortestng
). If you want more help from the community, I strongly suggest you to create another question related to this new problem and provide the entire stack trace, your POM, and anything you find interesting to describe this error.
– norbjd
Mar 26 at 8:58
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55303475%2fhow-to-create-and-run-docker-image-using-maven-from-dockerfile%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
C:/docker/
is not a valid path in maven:3.6.0-jdk-8
image, you should have used something like /docker/
instead.
The following Dockerfile
:
FROM maven:3.6.0-jdk-8
COPY pom.xml /docker/
COPY testng.xml /docker/
COPY src /docker/
RUN cd /docker/ && mvn clean verify
should work and run mvn clean verify
in a Docker container. You could also set the working directory to avoid repeating /docker/
everywhere :
FROM maven:3.6.0-jdk-8
RUN mkdir /docker
WORKDIR /docker
COPY pom.xml .
COPY testng.xml .
COPY src .
RUN mvn clean verify
Finally, a little trick when building with Maven like you do (outside the scope of your question but good to know) : you can significantly reduce the time of your build by downloading dependencies (using mvn dependency:resolve
) just after the COPY pom.xml /docker/
directive, like :
FROM maven:3.6.0-jdk-8
RUN mkdir /docker
WORKDIR /docker
COPY pom.xml .
RUN mvn dependency:resolve
COPY testng.xml .
COPY src .
RUN mvn clean verify
By doing so, if you build your image twice, but just updating files in src
folder the 2nd time, Docker will be able to use the cached layer and restart from COPY src .
layer (therefore not re-downloading all dependencies). But of course, if you update your pom.xml
, Docker will re-download all dependencies during the next build.
I have modified the Dockerfile as per your suggestion and try to build the image usingdocker build -t sample .
. but i got the error saying "There was an error in Forked Process , Cannot find class in classpath: TestRunner , org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process ". Please let me know if you can help me .
– user1553680
Mar 25 at 0:53
This error is related to Maven, do you have the same error when building locally (not inside the container)?
– norbjd
Mar 25 at 9:56
nope . It worked fine .
– user1553680
Mar 25 at 13:31
It should be related to your tests configuration (maven-surefire-plugin
,JUnit
ortestng
). If you want more help from the community, I strongly suggest you to create another question related to this new problem and provide the entire stack trace, your POM, and anything you find interesting to describe this error.
– norbjd
Mar 26 at 8:58
add a comment |
C:/docker/
is not a valid path in maven:3.6.0-jdk-8
image, you should have used something like /docker/
instead.
The following Dockerfile
:
FROM maven:3.6.0-jdk-8
COPY pom.xml /docker/
COPY testng.xml /docker/
COPY src /docker/
RUN cd /docker/ && mvn clean verify
should work and run mvn clean verify
in a Docker container. You could also set the working directory to avoid repeating /docker/
everywhere :
FROM maven:3.6.0-jdk-8
RUN mkdir /docker
WORKDIR /docker
COPY pom.xml .
COPY testng.xml .
COPY src .
RUN mvn clean verify
Finally, a little trick when building with Maven like you do (outside the scope of your question but good to know) : you can significantly reduce the time of your build by downloading dependencies (using mvn dependency:resolve
) just after the COPY pom.xml /docker/
directive, like :
FROM maven:3.6.0-jdk-8
RUN mkdir /docker
WORKDIR /docker
COPY pom.xml .
RUN mvn dependency:resolve
COPY testng.xml .
COPY src .
RUN mvn clean verify
By doing so, if you build your image twice, but just updating files in src
folder the 2nd time, Docker will be able to use the cached layer and restart from COPY src .
layer (therefore not re-downloading all dependencies). But of course, if you update your pom.xml
, Docker will re-download all dependencies during the next build.
I have modified the Dockerfile as per your suggestion and try to build the image usingdocker build -t sample .
. but i got the error saying "There was an error in Forked Process , Cannot find class in classpath: TestRunner , org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process ". Please let me know if you can help me .
– user1553680
Mar 25 at 0:53
This error is related to Maven, do you have the same error when building locally (not inside the container)?
– norbjd
Mar 25 at 9:56
nope . It worked fine .
– user1553680
Mar 25 at 13:31
It should be related to your tests configuration (maven-surefire-plugin
,JUnit
ortestng
). If you want more help from the community, I strongly suggest you to create another question related to this new problem and provide the entire stack trace, your POM, and anything you find interesting to describe this error.
– norbjd
Mar 26 at 8:58
add a comment |
C:/docker/
is not a valid path in maven:3.6.0-jdk-8
image, you should have used something like /docker/
instead.
The following Dockerfile
:
FROM maven:3.6.0-jdk-8
COPY pom.xml /docker/
COPY testng.xml /docker/
COPY src /docker/
RUN cd /docker/ && mvn clean verify
should work and run mvn clean verify
in a Docker container. You could also set the working directory to avoid repeating /docker/
everywhere :
FROM maven:3.6.0-jdk-8
RUN mkdir /docker
WORKDIR /docker
COPY pom.xml .
COPY testng.xml .
COPY src .
RUN mvn clean verify
Finally, a little trick when building with Maven like you do (outside the scope of your question but good to know) : you can significantly reduce the time of your build by downloading dependencies (using mvn dependency:resolve
) just after the COPY pom.xml /docker/
directive, like :
FROM maven:3.6.0-jdk-8
RUN mkdir /docker
WORKDIR /docker
COPY pom.xml .
RUN mvn dependency:resolve
COPY testng.xml .
COPY src .
RUN mvn clean verify
By doing so, if you build your image twice, but just updating files in src
folder the 2nd time, Docker will be able to use the cached layer and restart from COPY src .
layer (therefore not re-downloading all dependencies). But of course, if you update your pom.xml
, Docker will re-download all dependencies during the next build.
C:/docker/
is not a valid path in maven:3.6.0-jdk-8
image, you should have used something like /docker/
instead.
The following Dockerfile
:
FROM maven:3.6.0-jdk-8
COPY pom.xml /docker/
COPY testng.xml /docker/
COPY src /docker/
RUN cd /docker/ && mvn clean verify
should work and run mvn clean verify
in a Docker container. You could also set the working directory to avoid repeating /docker/
everywhere :
FROM maven:3.6.0-jdk-8
RUN mkdir /docker
WORKDIR /docker
COPY pom.xml .
COPY testng.xml .
COPY src .
RUN mvn clean verify
Finally, a little trick when building with Maven like you do (outside the scope of your question but good to know) : you can significantly reduce the time of your build by downloading dependencies (using mvn dependency:resolve
) just after the COPY pom.xml /docker/
directive, like :
FROM maven:3.6.0-jdk-8
RUN mkdir /docker
WORKDIR /docker
COPY pom.xml .
RUN mvn dependency:resolve
COPY testng.xml .
COPY src .
RUN mvn clean verify
By doing so, if you build your image twice, but just updating files in src
folder the 2nd time, Docker will be able to use the cached layer and restart from COPY src .
layer (therefore not re-downloading all dependencies). But of course, if you update your pom.xml
, Docker will re-download all dependencies during the next build.
edited Mar 22 at 20:54
answered Mar 22 at 20:43
norbjdnorbjd
2,1252929
2,1252929
I have modified the Dockerfile as per your suggestion and try to build the image usingdocker build -t sample .
. but i got the error saying "There was an error in Forked Process , Cannot find class in classpath: TestRunner , org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process ". Please let me know if you can help me .
– user1553680
Mar 25 at 0:53
This error is related to Maven, do you have the same error when building locally (not inside the container)?
– norbjd
Mar 25 at 9:56
nope . It worked fine .
– user1553680
Mar 25 at 13:31
It should be related to your tests configuration (maven-surefire-plugin
,JUnit
ortestng
). If you want more help from the community, I strongly suggest you to create another question related to this new problem and provide the entire stack trace, your POM, and anything you find interesting to describe this error.
– norbjd
Mar 26 at 8:58
add a comment |
I have modified the Dockerfile as per your suggestion and try to build the image usingdocker build -t sample .
. but i got the error saying "There was an error in Forked Process , Cannot find class in classpath: TestRunner , org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process ". Please let me know if you can help me .
– user1553680
Mar 25 at 0:53
This error is related to Maven, do you have the same error when building locally (not inside the container)?
– norbjd
Mar 25 at 9:56
nope . It worked fine .
– user1553680
Mar 25 at 13:31
It should be related to your tests configuration (maven-surefire-plugin
,JUnit
ortestng
). If you want more help from the community, I strongly suggest you to create another question related to this new problem and provide the entire stack trace, your POM, and anything you find interesting to describe this error.
– norbjd
Mar 26 at 8:58
I have modified the Dockerfile as per your suggestion and try to build the image using
docker build -t sample .
. but i got the error saying "There was an error in Forked Process , Cannot find class in classpath: TestRunner , org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process ". Please let me know if you can help me .– user1553680
Mar 25 at 0:53
I have modified the Dockerfile as per your suggestion and try to build the image using
docker build -t sample .
. but i got the error saying "There was an error in Forked Process , Cannot find class in classpath: TestRunner , org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process ". Please let me know if you can help me .– user1553680
Mar 25 at 0:53
This error is related to Maven, do you have the same error when building locally (not inside the container)?
– norbjd
Mar 25 at 9:56
This error is related to Maven, do you have the same error when building locally (not inside the container)?
– norbjd
Mar 25 at 9:56
nope . It worked fine .
– user1553680
Mar 25 at 13:31
nope . It worked fine .
– user1553680
Mar 25 at 13:31
It should be related to your tests configuration (
maven-surefire-plugin
, JUnit
or testng
). If you want more help from the community, I strongly suggest you to create another question related to this new problem and provide the entire stack trace, your POM, and anything you find interesting to describe this error.– norbjd
Mar 26 at 8:58
It should be related to your tests configuration (
maven-surefire-plugin
, JUnit
or testng
). If you want more help from the community, I strongly suggest you to create another question related to this new problem and provide the entire stack trace, your POM, and anything you find interesting to describe this error.– norbjd
Mar 26 at 8:58
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55303475%2fhow-to-create-and-run-docker-image-using-maven-from-dockerfile%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown