Code Monkey home page Code Monkey logo

Comments (9)

nbentoneves avatar nbentoneves commented on August 30, 2024 4

Ohhh I found the solution. You can read this tutorial: https://g00glen00b.be/docker-spring-boot/. The problem is your application load the application.properties.
You need to change the ENTRYPOINT to load the profile with the container configuration (application.yml). E.g "-Dspring.profiles.active=container"

spring:
    profiles: container
    jpa:
        database: MYSQL
        hibernate:
            ddl-auto: validate

    datasource:
        url: jdbc:mysql://mysql:3306/tsbacked
        username: root
        password: 12345
        driver-class-name: com.mysql.jdbc.Driver

from gs-spring-boot-docker.

nbentoneves avatar nbentoneves commented on August 30, 2024

It's happened the same to me. I tried to use the --link docker parameter when running my app but continue not working. Do you already found any solution? Thanks

from gs-spring-boot-docker.

DILEEP-YADAV avatar DILEEP-YADAV commented on August 30, 2024

thanks

from gs-spring-boot-docker.

DILEEP-YADAV avatar DILEEP-YADAV commented on August 30, 2024

docker run -p 8080:8080 -t 770727c11311
Error: Invalid or corrupt jarfile /app.jar

I am using the following sample app to make my own docker image
https://github.com/spring-guides/gs-spring-boot-docker.git

docker image builds successfully. and working fine with my laptop with docker terminal for windows 10.
but the same image pushed to gitlab docker registry. and using my VPS Centos server. it is getting the same error. Please help me. Or even pulling to same docker image to docker terminal for windows 10. getting the same error.
error

from gs-spring-boot-docker.

nbentoneves avatar nbentoneves commented on August 30, 2024

Could be a lot of problems...you can find many problem related to "INVALID OR CORRUPT JARFILE" on the internet!
I recommend extracting the jar file (downloaded) and compare to the files with the jar generated locally. (You can compare the size of jar).

Can you show me your dockerfile, please?

from gs-spring-boot-docker.

DILEEP-YADAV avatar DILEEP-YADAV commented on August 30, 2024

FROM openjdk:8-jre
VOLUME /tmp
ARG JAR_FILE
ADD ${JAR_FILE} techlaviya.jar
RUN bash -c 'touch /techlaviya.jar'
EXPOSE 8080
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-Dspring.profiles.active=container","-jar","/techlaviya.jar"]

from gs-spring-boot-docker.

DILEEP-YADAV avatar DILEEP-YADAV commented on August 30, 2024

version: '3'

services:
docker-mysql:
image: mysql:latest
environment:
- MYSQL_ROOT_PASSWORD=12345
- MYSQL_DATABASE=TechlaviyaDB
- MYSQL_PASSWORD=12345

phpmyadmin:
image: phpmyadmin/phpmyadmin
links:
- docker-mysql
environment:
PMA_HOST: docker-mysql
PMA_PORT: 3306
ports:
- '8081:80'
docker-webapp:
image: techlaviya/techlaviya:0.0.1-SNAPSHOT
depends_on:
- docker-mysql
ports:
- 8080:8080
environment:
- DATABASE_HOST=docker-mysql
- DATABASE_USER=root
- DATABASE_PASSWORD=12345
- DATABASE_NAME=TechlaviyaDB
- DATABASE_PORT=3306

from gs-spring-boot-docker.

DILEEP-YADAV avatar DILEEP-YADAV commented on August 30, 2024


4.0.0

<groupId>com.tech.techlaviya</groupId>
<artifactId>techlaviya</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>techlaviya</name>
<description>Techlaviya Rest API Project</description>

<parent>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-parent</artifactId>
	<version>1.5.9.RELEASE</version>
	<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
	<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
	<java.version>1.8</java.version>
	<spring-cloud.version>Dalston.RELEASE</spring-cloud.version>
	<start-class>com.tech.techlaviya.TechlaviyaApplication</start-class>
	<docker.image.prefix>techlaviya</docker.image.prefix>
</properties>

<dependencies>
	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-web</artifactId>
	</dependency>
	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-data-jpa</artifactId>
	</dependency>

	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-devtools</artifactId>
		<scope>runtime</scope>
	</dependency>
	<dependency>
		<groupId>mysql</groupId>
		<artifactId>mysql-connector-java</artifactId>
	</dependency>

	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-test</artifactId>
		<scope>test</scope>
	</dependency>

	<dependency>
		<groupId>com.jayway.jsonpath</groupId>
		<artifactId>json-path</artifactId>
		<scope>test</scope>
	</dependency>


	<dependency>
		<groupId>io.springfox</groupId>
		<artifactId>springfox-swagger2</artifactId>
		<version>2.4.0</version>
	</dependency>
	<dependency>
		<groupId>io.springfox</groupId>
		<artifactId>springfox-swagger-ui</artifactId>
		<version>2.4.0</version>
	</dependency>


	<dependency>
		<groupId>io.jsonwebtoken</groupId>
		<artifactId>jjwt</artifactId>
		<version>0.6.0</version>
	</dependency>
	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-security</artifactId>
	</dependency>
	<dependency>
		<groupId>com.fasterxml.jackson.core</groupId>
		<artifactId>jackson-core</artifactId>
		<version>2.8.9</version>
	</dependency>

	<dependency>
		<groupId>org.springframework.mobile</groupId>
		<artifactId>spring-mobile-device</artifactId>
	</dependency>

	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-data-rest</artifactId>
	</dependency>

</dependencies>
<dependencyManagement>
	<dependencies>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-dependencies</artifactId>
			<version>${spring-cloud.version}</version>
			<type>pom</type>
			<scope>import</scope>
		</dependency>
	</dependencies>
</dependencyManagement>

<build>
	<finalName>techlaviya</finalName>
	<plugins>
		<plugin>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-maven-plugin</artifactId>
		</plugin>
		<plugin>
			<artifactId>maven-jar-plugin</artifactId>
			<configuration>
				<archive>
					<manifest>
						<addClasspath>true</addClasspath>
						<classpathPrefix>lib/</classpathPrefix>
						<mainClass>com.tech.techlaviya.TechlaviyaApplication</mainClass>
					</manifest>
				</archive>
			</configuration>
		</plugin>
		<!-- tag::plugin[] -->
		<plugin>
			<groupId>com.spotify</groupId>
			<artifactId>dockerfile-maven-plugin</artifactId>
			<version>1.3.6</version>
			<executions>
				<execution>
					<id>default</id>
					<goals>
						<goal>build</goal>
						<goal>push</goal>
					</goals>
				</execution>
			</executions>
			<configuration>
				<repository>${docker.image.prefix}/${project.artifactId}</repository>
				<tag>${project.version}</tag>
				<buildArgs>
					<JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
				</buildArgs>
			</configuration>


		</plugin>
		<!-- end::plugin[] -->
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-dependency-plugin</artifactId>
			<executions>
				<execution>
					<id>unpack</id>
					<phase>package</phase>
					<goals>
						<goal>unpack</goal>
					</goals>
					<configuration>
						<artifactItems>
							<artifactItem>
								<groupId>${project.groupId}</groupId>
								<artifactId>${project.artifactId}</artifactId>
								<version>${project.version}</version>
							</artifactItem>
						</artifactItems>
					</configuration>
				</execution>
			</executions>
		</plugin>
	</plugins>
</build>

from gs-spring-boot-docker.

dsyer avatar dsyer commented on August 30, 2024

Running with a database is out of scope for this guide. If you want to see some guidance, maybe open an issue in the extended topical guide.

from gs-spring-boot-docker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.