1

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
  • 2,526
  • 1
  • 8
  • 18
Krzysztof Suc
  • 45
  • 1
  • 5
  • Please show the work. What are the commands used to start both? What are the `Dockerfiles`? What are the log output of both? One guess is that the hostname is not available on default Docker network. You need to create your own network for DNS to resolve container names. – Andy Shinn Aug 10 '20 at 15:48
  • I think you should try localhost:8888 but to be sure can you show your docker compose or/and docker run command? – J Asgarov Aug 10 '20 at 15:48
  • @JAsgarov yes, i connect with localhost, but i think is it not correctly. – Krzysztof Suc Aug 10 '20 at 15:52
  • Like i said your server is running on localhost, port 8888 = http://localhost:8888 – J Asgarov Aug 10 '20 at 15:57
  • @JAsgarov yes, but shouldn't I refer to it by container name? – Krzysztof Suc Aug 10 '20 at 15:59
  • container name is for docker cli commands, now you can execute commands like docker container stop "container-name", not for specifying the dns name. DNS name is necessary for outside calls, from computer that has docker running you can always use localhost – J Asgarov Aug 10 '20 at 16:03
  • @JAsgarov ok I understand. I have one more question for you. How do I build a .jar file. When I change the uri address in discavery-server to localhost and build the file, it won't work when I run docker-compose. – Krzysztof Suc Aug 10 '20 at 16:17

1 Answers1

0

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.

J Asgarov
  • 2,526
  • 1
  • 8
  • 18