简体   繁体   English

在Docker容器中运行时无法从Spring Cloud Config Server获取配置

[英]Unable to get Configuration from Spring Cloud Config Server while its running within a Docker Container

I have been working on trying to resolve this issue for a day, and have had no luck, I am really stumped on what the error is. 我一直在努力解决这一问题,有一天没有运气,我真的很困惑这个错误是什么。 I have created a simple Spring Cloud Config Server using Spring Boot version 1.5.9.RELEASE and Spring Cloud Edgware.RELEASE. 我使用Spring Boot版本1.5.9.RELEASE和Spring Cloud Edgware.RELEASE创建了一个简单的Spring Cloud Config Server。 My Config Repo is a bitbucket repository. 我的配置仓库是一个位桶存储库。 For Docker I am using the fabric8 maven docker plugin to build the docker image, and its deployed on Docker for Mac. 对于Docker,我正在使用fabric8 maven docker插件来构建docker镜像,并将其部署在Mac的Docker上。 I am also using Java 9. I am able to build my docker image, and run it on port 8888 but when I invoke the health endpoint it is "Down". 我也使用Java9。我能够构建docker映像,并在端口8888上运行它,但是当我调用运行状况端点时,它是“ Down”。 When I try to run the following Get Request ( http://localhost:8888/sample-api/dev ), I get the following error: 当我尝试运行以下Get Request( http:// localhost:8888 / sample-api / dev )时,出现以下错误:

{
    "timestamp": 1515552923667,
    "status": 404,
    "error": "Not Found",
    "exception": "org.springframework.cloud.config.server.environment.NoSuchRepositoryException",
    "message": "Cannot clone or checkout repository: https://bitbucket.org/<project>/<repo>.git",
    "path": "/sample-api/dev"
}

Below is my Dockerfile, any sensitive data has been removed 以下是我的Dockerfile,所有敏感数据均已删除

FROM openjdk:9
ENV PROFILE dev
VOLUME /config
ADD /maven/*.jar app.jar
EXPOSE 8888
RUN bash -c 'touch /app.jar'
WORKDIR /
ENTRYPOINT exec java -Dspring.profiles.active=$PROFILE -Djava.security.egd=file:/dev/./urandom -jar /app.jar

Below is my application yaml file: 以下是我的应用程序yaml文件:

server:
  port: 8888
spring:
  application:
    name: sample-config-server
  cloud:
    config:
      server:
        encrypt:
          enabled: false
        git:
          uri: https://bitbucket.org/<project>/<repo>.git
          username: ${GIT_USER_NAME}
          password: ${GIT_PASSWORD}

username: ${CLOUD_CONFIG_NAME}
password: ${CLOUD_CONFIG_PASSWORD}

Below are the commands I use to run this with docker: 以下是我用于在docker上运行的命令:

mvn clean package docker:build
docker run -p 8888:8888 -d sample/<sample-config-server:latest

When I run locally using, mvn -Dspring.profiles.active=dev spring-boot:run, everything works as expected. 当我使用mvn -Dspring.profiles.active = dev spring-boot:run在本地运行时,一切正常。 It is only when I run within Docker for Mac when I get the 404 error. 仅当我收到404错误时,才在Mac的Docker中运行。 I tried sshing into the container and cloning my git repo manually, I was able to do that with no problem. 我尝试将其切入容器并手动克隆git repo,我能够做到这一点没有问题。 The issue has to be with my Spring Cloud configuration or even Spring Cloud Config Project itself, I don't know. 我不知道问题出在我的Spring Cloud配置甚至是Spring Cloud Config Project本身。

Has anyone faced this issue before? 有人遇到过这个问题吗? Can anyone replicate this issue? 谁能复制这个问题?

Update: 更新:

I have run the same container in minikube and I still get this same issue... I am working round the clock trying to resolve this issue, but no success yet. 我在minikube中运行了相同的容器,但仍然遇到相同的问题...我全天候工作以尝试解决此问题,但尚未成功。 I will keep you updated. 我会及时通知你的。

I was finally able to resolve the issue. 我终于能够解决问题。 This had nothing to do with Spring Cloud Config or my Spring Cloud Config configuration. 这与Spring Cloud Config或我的Spring Cloud Config配置无关。 After careful analysis of logs, I saw the following error coming from JGit: 在仔细分析日志后,我发现来自JGit的以下错误:

java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty

It seems like the openJDK 9 docker image was missing content in its cacerts file, preventing JGit from making a successful https connection to bitbucket, thus resulting in the NoSuchRepositoryException. 似乎openJDK 9 docker映像缺少其cacerts文件中的内容,从而阻止JGit与位桶建立成功的https连接,从而导致NoSuchRepositoryException。 I searched the issue an found this link on the subject: 我搜索了此问题,并在该主题上找到了此链接:

https://github.com/docker-library/openjdk/issues/145 https://github.com/docker-library/openjdk/issues/145

From what I read in the link, it was recommended to use 9-jdk-slim instead of 9-jdk, since 9-jdk-slim did not have the empty cacerts file. 根据我在链接中看到的内容,建议使用9-jdk-slim而不是9-jdk,因为9-jdk-slim没有空的cacerts文件。

In my Dockerfile, I change the FROM statement to use 9-jdk-slim instead of 9-jdk. 在我的Dockerfile中,我将FROM语句更改为使用9-jdk-slim而不是9-jdk。 I rebuilt the image using the Maven Fabric 8 plugin, and ran the image as a container. 我使用Maven Fabric 8插件重建了图像,然后将图像作为容器运行。 I was successfully able to get configurations from Bitbucket via the Spring Cloud Config server. 我能够通过Spring Cloud Config服务器成功从Bitbucket获取配置。 This worked in Docker for Mac and in Minikube. 这适用于Mac的Docker和Minikube。 My lesson learned is to fully enable logging in Spring Boot, and conduct a careful and through analysis of the logs to resolve issues like this. 我的经验教训是完全启用Spring Boot中的日志记录,并仔细分析日志以解决此类问题。 I hope this helps other developers with similar issues. 希望这对其他有类似问题的开发人员有所帮助。

1) Your references to ports in host and container refer to 8888 but link you included says http://localhost:8080/sample-api/dev . 1)您对主机和容器中端口的引用指的是8888,但您包含的链接表示http://localhost:8080/sample-api/dev Is it a typo or maybe you have another app listening on port 8080. 是错字,还是您在端口8080上监听了另一个应用程序。

The Config server could be queried using these formats: 可以使用以下格式查询配置服务器:

/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties

How is the properties file named in your Bitbucket repo? 在您的Bitbucket存储库中如何命名属性文件?

BTW, I have blogged about this exact topic with source code and docker image available, it might help you to get started with yours: 顺便说一句,我已经在博客上写了这个确切的主题,提供了源代码和docker镜像,它可能会帮助您入门:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用用于Git的SSH密钥并在Docker中运行的Spring Cloud Config Server - Spring Cloud Config Server using SSH key for Git and running in Docker Docker 容器中的 Spring Cloud Config 无法访问 - Spring Cloud Config in Docker container is not accessible Spring 作为 Docker 容器启动时,启动服务无法连接到 Spring 云配置服务器 - Spring Boot service can't connect to Spring Cloud Config Server when start as a Docker container Docker-compose:在启用spring boot和spring cloud config应用程序时出现问题 - Docker-compose: Issue while running the spring boot enabled and spring cloud config application 为Spring Cloud Config Server创建Docker文件 - Create docker file for spring cloud config server 从mssql-server docker容器中运行“ dotnet测试” - Running “dotnet test” from within a mssql-server docker container 在局域网内的Docker容器中运行的服务器无响应 - No response from server running in Docker container within LAN 无法在正在运行的 Docker 容器中使用 ssh localhost - Unable to ssh localhost within a running Docker container Spring 在 Docker 上运行时忽略安全配置 - Spring Security config ignored while running on Docker Docker CMD 命令在启动容器时不执行,但在容器内运行时有效 - Docker CMD commad does not execute while running starting the container but works when run from within the container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM