Reputation: 25
I am new in docker. I have a springboot application which is running on jboss-eap-7.2. Usually when I want to run the application, first I have to run command mvn clean package in cmd and then after build success, I run standalone.bat -c standalone_wingsure.xml, and it works fine. I want to run this application in docker container. So I created a DockerFile, which include this code.
FROM openjdk:8
ADD target/wingsure_crop_insurance-0.0.1.war wingsure_crop_insurance-0.0.1.war
EXPOSE 8080
ENTRYPOINT ["java", "-war", "wingsure_crop_insurance-0.0.1.war"]
This springboot application has mysql database connection. So I created docker container for mysql image. Here is my appliaction.properties file .
spring.datasource.url=jdbc:mysql://mysql-standalone:3306/crop_insurance
spring.datasource.username=chronito
spring.datasource.password=mysql
My pom.xml -
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.wingsure</groupId>
<artifactId>wingsure_crop_insurance</artifactId>
<version>0.0.1</version>
<packaging>war</packaging>
<name>wingsure_crop_insurance</name>
<description>Crop Insurance</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<!-- <version>3.1.0</version> -->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency> -->
<!-- https://mvnrepository.com/artifact/org.springframework.security.oauth/spring-security-oauth2 -->
<!-- <dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.3.5.RELEASE</version>
</dependency> -->
<dependency>
<groupId>botlibre-ai</groupId>
<artifactId>botlibre-ai</artifactId>
<scope>system</scope>
<version>1.0</version>
<systemPath>${basedir}\src\lib\botlibre-ai.jar</systemPath>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>27.1-jre</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<outputDirectory>${env.JBOSS_HOME}/standalone/deployments/</outputDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
</plugin>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>com.wingsure.WingsureCropInsuranceApplication</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
After mvn clean install the war file is generated in /target folder.
Then I build the image for the application by running command D:\chronito\checkout\wingsure_crop_insurance\wingsure_crop_insurance>docker build . -t wingsure_crop_insurance-0.0.1
After building image I run the image in container by linking with mysql container and it successfully runs the container without any error.
D:\chronito\checkout\wingsure_crop_insurance\wingsure_crop_insurance>docker run -p 8080:8080 --name wingsure_crop_insurance-0.0.1 --link mysql-standalone:mysql -d wingsure_crop_insurance-0.0.1
7db57549b4c94ee0546275b962482a95b215f7aaf576be3d82340ec1934f117f
But when I see the logs I get the error like this -
D:\chronito\checkout\wingsure_crop_insurance\wingsure_crop_insurance>docker logs wingsure_crop_insurance-0.0.1
Unrecognized option: -war
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
I don't know what I am doing wrong. Any suggestion would be very helpful.
After EbrahimPasbani's solution the previous error is gone, but it did not startup the springboot application. After I run the docker command
D:\chronito\checkout\wingsure_crop_insurance\wingsure_crop_insurance>docker run -p 8080:8080 --name wingsure_crop_insurance-0.0.1 --link mysql-standalone:mysql -d wingsure_crop_insurance-0.0.1
7b3836cb4da2d6ab1c1a55b1fa2c3ac500c99372313388cdeb54f24249e073bd
it successfully run the container and shows the logs as
=========================================================================
12:34:52,374 INFO [org.jboss.modules] (main) JBoss Modules version 1.8.6.Final-redhat-00001
I> No access restrictor found, access to any MBean is allowed
Jolokia: Agent started with URL https://172.17.0.3:8778/jolokia/
12:34:53,501 INFO [org.jboss.msc] (main) JBoss MSC version 1.4.5.Final-redhat-00001
12:34:53,520 INFO [org.jboss.threads] (main) JBoss Threads version 2.3.2.Final-redhat-1
The main class is -
@SpringBootApplication
@EnableConfigurationProperties({
FileStorageProperties.class
})
public class WingsureCropInsuranceApplication extends
SpringBootServletInitializer{
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder
application)
{
return application.sources(WingsureCropInsuranceApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(WingsureCropInsuranceApplication.class, args);
}
}
Upvotes: 2
Views: 1883
Reputation: 9406
The java
command does not have -war
option.
If you want to use jboss then you need to deploy your war to jboss in docker.
So the docker file should be from jboss like below:
#start from eap72-openshift
FROM registry.access.redhat.com/jboss-eap-7/eap72-openshift
# Copy war to deployments folder
COPY target/wingsure_crop_insurance-0.0.1.war $JBOSS_HOME/standalone/deployments/
# User root to modify war owners
USER root
# Modify owners war
RUN chown jboss:jboss $JBOSS_HOME/standalone/deployments/wingsure_crop_insurance-0.0.1.war
# Important, use jboss user to run image
USER jboss
Upvotes: 1