Exception when running Spring Boot app inside of Docker

Krzysztof Suc :

I have a problem connecting to the config-server. I am not sure what am I doing wrong. I have configured server running in a docker container named "config-server" on port 8888.

http://config-server:8888. Will be trying the next url if available
2020-08-10 17:38:35.196 ERROR 11052 --- [           main] o.s.boot.SpringApplication               : Application run failed

java.lang.IllegalStateException: Could not locate PropertySource and the fail fast property is set, failing
    at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.locate(ConfigServicePropertySourceLocator.java:148) ~[spring-cloud-config-client-2.2.3.RELEASE.jar:2.2.3.RELEASE]

discovery-server bootstrap.yml

spring:
  application:
    name: discovery-server
  cloud:
    config:
      uri: http://config-server:8888
      fail-fast: true
      retry:
        max-attempts: 20

EDIT
config-server Dockerfile

FROM openjdk:11.0-jre
ADD ./target/config-server-0.0.1-SNAPSHOT.jar config-server-0.0.1-SNAPSHOT.jar
ENTRYPOINT ["java", "-jar", "/config-server-0.0.1-SNAPSHOT.jar"]
EXPOSE 8888

docker run -p 8888:8888 --name config-server 3deb982c96fe
Discavery-server is not running in docker. First I want to create its .jar file

J Asgarov :

Original question already answered in comments, answering the last point here for better formatting:

Jar file will be built in /target folder of your application everytime you run mvn clean install or gradle build. In order to run this in Docker you have to copy the jar file from your /target directory to the Docker container inner files, and then run it (java -jar nameOfYourJar.jar).

Name of your jar can be defined in maven/gradle settings but to keep your Dockerfile generic I suggest following Dockerfile:

FROM openjdk:11.0-jre
ARG JAR_FILE=/target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","app.jar"]

with ARG JAR_FILE you save the path to any jar file (found in target) as JAR_FILE variable in docker and then you can copy it to your Docker inner files where it will be stored under the name app.jar.

ENTRYPOINT is the command that will be run on container start.

Place the Dockerfile next to the /target directory (so in root folder of your app) and run following command in terminal:

docker build -t springapp . && docker run --rm -d -p 8080:8080 springapp

Hope this clarifies everything.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Running Spring Boot app inside Docker container, unable to connect MySQL

How to do a health-check to Spring Boot app running inside Windows Docker Windows Container with Ansible?

Docker error when containerizing a spring boot app

Error while running spring boot on external tomcat inside docker container

Docker MongoDB - Exception opening socket from containerized Spring Boot app

Pass command line args to Java app (Spring Boot) running in Docker

Connection refused by Spring boot app running in different docker container

spring boot app not connecting to activemq which is running in a docker container

failed to initialize Tomcat while running Spring boot app with vaadin in docker

Getting an exception when starting a Spring-boot app

Java app working when running spring boot but not with Apache

JVM crashes when running Spring Boot web app

Feign UnsatisfiedDependecyException when running my spring boot app

Spring Boot + Postgresql not creating table when running app

JSF components are not rendered when running Spring Boot app on Eclipse Tomcat

Always getting 404 when running Spring Boot Gradle app in IntelliJ

CORS errors when deploying Spring Boot and Angular app in Docker

Exception from running spring-boot-legacy

Exception while running Spring boot cassandra project

Running a Spring Boot Camel inside Jboss Fuse

Cannot see Log information in Kibana running in Docker Container in my Spring Boot App (ELK)

Spring Boot docker microservices restTemplate exception

Unable to load Spring Boot application running in Docker

Spring boot docker running on 8080 only?

Fatal error when running a JavaFX GUI app inside Eclipse in a Docker container

Exception Handler not working on a spring boot app

Spring boot web app not running on tomcat 9

Spring Boot Testing - Keep the App running for longer

Spring Boot ApplicationListener not running at app startup