0

Error :

Failed to execute goal com.spotify:docker-maven-plugin:1.0.0:build (default-cli) on project Bookstore: Exception caught: java.util.concurrent.ExecutionException: com.spotify.docker.client.shaded.javax.ws.rs.ProcessingException: org.apache.http.NoHttpResponseException: localhost:2377 failed to respond 

DockerFile:

FROM tomcat:8-alpine
EXPOSE 2377:8080
ADD /WebContent/WEB-INF/web.xml /usr/local/tomcat/conf/
VOLUEME /tmp/webappdata/
COPY /target/Bookstore-1.war /usr/local/tomcat/webapps/
RUN sh -c 'touch /usr/local/tomcat/webapps/Bookstore-1.war'
ENTRYPOINT ["sh", "-c" , "java -Djava.security.edg=file:/dev/./urandom -jar /usr/local/tomcat/webapps/Bookstore-1.war]

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>net.codejava.javaee.bookstore</groupId>
  <artifactId>Bookstore</artifactId>
  <version>1</version>
  <packaging>war</packaging>

    <properties>
    <docker.image.prefix>alesblaze</docker.image.prefix>
    </properties>

    <dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>javax.servlet.jsp-api</artifactId>
            <version>2.3.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.30</version>
        </dependency>
    </dependencies>  

  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.5.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.6</version>
        <configuration>
        <finalName>BookStore</finalName>
          <warSourceDirectory>WebContent</warSourceDirectory>
          <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
      </plugin>

      <plugin>
    <groupId>com.spotify</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <version>1.0.0</version>
    <configuration>
    <imageName>${docker.image.prefix}/${project.artifactId}</imageName>
    <dockerDirectory>Docker</dockerDirectory>
    <dockerHost>http://localhost:2377</dockerHost>
    <forceTags>true</forceTags>
    <imageTags>
    <imageTag>${project.version}</imageTag>
    <imageTag>latest</imageTag>
    </imageTags>
    <serverId>docker-hub</serverId>
    <registryUrl>http://hub.docker.com/</registryUrl>
    <resources>
    <resource>
    <targetPath>/</targetPath>
    <directory>${project.build.directory}</directory>
    <include>${project.build.finalName}.war</include>
    </resource>
    </resources>
    </configuration>
<!--    <executions> -->
<!--    <execution> -->
<!--    <phase>package</phase> -->
<!--    <goals> -->
<!--    <goal>build</goal> -->
<!--    </goals> -->
<!--    </execution> -->
<!--    </executions> -->
</plugin>

    </plugins>
  </build>

</project>

May someone explain me what going wrong here and how to resolve it?

I am trying to deploy a sample java web app in a container running tomcat and i am using maven to build war file , but when i run mvn clean package docker:build (i am using maven's spotify plugin to build dockerfile)

In build phase , it shows the NoHttpResponseException , what is going wrong behind the scenes?

Arjun Sharma
  • 101
  • 2
  • 2
  • 10
  • Can you just delete the `` line? If that works, I can explain why. – David Maze Sep 22 '19 at 11:16
  • Connection refused exception occured after removal of the `` from pom.xml. `[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:1.0.0:build (default-cli) on project Bookstore: Exception caught: java.util.concurrent.ExecutionException: com.spotify.docker.client.shaded.javax.ws.rs.ProcessingException: java.io.IOException: Connection refused` – Arjun Sharma Sep 22 '19 at 11:29
  • There's a typo: `VOLUEME`. Also, make sure you have proper permissions to write to /`usr/local/tomcat/webapps/`. – LMC Sep 23 '19 at 13:20
  • This will not work either `-jar /usr/local/tomcat/webapps/Bookstore-1.war`. You should pack your app as a jar. – LMC Sep 23 '19 at 13:24
  • @LuisMuñoz how can i make sure of the permissions to webapps directory, may you tell me? – Arjun Sharma Sep 23 '19 at 13:26
  • That's Linux regular stuff, you either own the directory or belong to the group and have write permissions to it. On `ls -l /user/local/` that will most rpobably show lines starting with `drwxr-xr-x 1 root root`, so those dirs belng to `root` and users in the `root` group can't write on those dirs. I suggest to look at the packing issue first. In other words, run the app as war or as jar. – LMC Sep 23 '19 at 13:32
  • @LuisMuñoz but i want to run war file , is there any other command to run it? Actually , i have gone through a tutorial and he used the same command in the dockerfile! If i am wrong somewhere just correct me, thankyou so much – Arjun Sharma Sep 23 '19 at 14:59
  • perhaps you have mixed tutorials, [here](https://aspetraining.com/resources/blog/deploying-your-first-web-app-to-tomcat-on-docker) is one about docker+tomcat as starting point. – LMC Sep 23 '19 at 15:33
  • @LuisMuñoz i really respect you , because you are the most responsive person helping me here , when i badly need the help, https://stackoverflow.com/q/58063317/9790334 , i would like you to visit this question of mine as its the problem that i am currently facing , thankyou so much for helping me! And i will look into the link. – Arjun Sharma Sep 23 '19 at 15:38
  • np, glad to help. – LMC Sep 23 '19 at 15:43

1 Answers1

0

Try port 8080, this is usually the default port for localhost.

Tal Angel
  • 1,301
  • 3
  • 29
  • 63