简体   繁体   English

如何为 Spring 云配置服务器的客户端服务构建 Docker 映像

[英]How to build a Docker image for client service of Spring Cloud Config Server

I have built a Docker image for cloud config service.我为云配置服务构建了一个 Docker 映像。 I have another service employee for which I want to build a Docker image.我有另一个服务employee ,我想为其构建 Docker 映像。 This client service will read data source configuration properties from the config server此客户端服务将从配置服务器读取数据源配置属性

I am able to connect the employee service successfully with config service on localhost without Docker.我能够在没有 Docker 的情况下成功地将employee服务与本地主机上的配置服务连接起来。 The problem is only that I am not able to build a Docker image for the employee service.问题只是我无法为employee服务构建 Docker 映像。

On running mvn package dockerfile:build command for the employee service I get the following error在为员工服务运行mvn package dockerfile:build命令时,我收到以下错误

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class

Below is the bootstrap.yml file located at src/main/resources directory下面是位于src/main/resources目录下的bootstrap.yml文件

spring:
  application:
    name: employee
  profiles:
    active: dev
  cloud:
    config:
      uri: http://configserver:8071

Config service's bootstrap.yml file配置服务的 bootstrap.yml 文件

spring:
  application:
    name: config-server
  profiles:
    active: native,dev
    
  cloud:
    config:
      server:
        #Local configuration: This locations can either of classpath or locations in the filesystem.
        native:
          #Reads from a specific filesystem folder 
          search-locations: classpath:/config
    
server:
  port: 8071

employee.properties file in config directory配置目录中的employee.properties 文件

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect

employee-dev.properties file员工-dev.properties 文件

spring.datasource.url=jdbc:mysql://db:3306/employee?allowPublicKeyRetrieval=true&useSSL=false
spring.datasource.username=root
spring.datasource.password=root

This is probably because the container of config server with hostname configserver is not up.这可能是因为主机名为configserver的配置服务器容器未启动。 I am not sure what hostname I should provide.我不确定我应该提供什么主机名。 Even if I want to build the image of employee service by starting the container of config server, it won't be on configserver host but on localhost .即使我想通过启动配置服务器的容器来构建employee服务的图像,它也不会在configserver主机上,而是在localhost上。 This is probably why the build is failing?这可能是构建失败的原因?

I want to build the Docker image of employee service so that its container can be fired up using the docker-compose up command我想构建员工服务的 Docker 映像,以便可以使用docker-compose up命令启动其容器

Edit: This question is similar but I already have the spring-cloud-starter-config dependency added in my client service and it still gives me the same error on build编辑:这个问题很相似,但我已经在我的客户端服务中添加了spring-cloud-starter-config依赖项,它仍然给我同样的构建错误

Edit 2编辑 2

You don't have to separately build a Docker image for the client service at all!您根本不必为客户端服务单独构建 Docker 映像!

When I ran docker-compose up command I noticed the following line in output当我运行docker-compose up命令时,我注意到 output 中的以下行

c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://configserver:8071

But I was still not sure if it was actually reading the data from the config server.但我仍然不确定它是否真的从配置服务器读取数据。 So I purposely added incorrect database credentials in config server properties file for my service and the service startup failed!所以我故意在配置服务器属性文件中为我的服务添加了不正确的数据库凭据,并且服务启动失败! Now I am sure that my employee service is reading the data from the config server现在我确定我的employee服务正在从配置服务器读取数据

I am still not sure how can I achieve creating a new Docker image for my employee service.我仍然不确定如何为我的employee服务创建一个新的 Docker 图像。

Did you try changing the URL param db to actual host of vhostname?您是否尝试将 URL 参数数据库更改为虚拟主机名的实际主机?

db =change it to IP addess or accessable load balancer URL db =将其更改为 IP 地址或可访问负载均衡器 URL

spring.datasource.url=jdbc:mysql://db:3306/employee?allowPublicKeyRetrieval=true&useSSL=false spring.datasource.url=jdbc:mysql://db:3306/employee?allowPublicKeyRetrieval=true&useSSL=false

暂无
暂无

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

相关问题 如何使用Docker来实现Spring Cloud Config Server安全性 - how to implement spring cloud config server security with docker Spring 作为 Docker 容器启动时,启动服务无法连接到 Spring 云配置服务器 - Spring Boot service can't connect to Spring Cloud Config Server when start as a Docker container 如何从 Spring 云客户端服务器使用 spring 云配置服务器 Jdbc 后端配置? - How to consume spring cloud config server Jdbc backend configs from Spring cloud Client server? 当 Spring Security 在 Spring Cloud Config Server 上处于活动状态时,Spring Cloud Config Client 不获取配置 - Spring Cloud Config Client not fetching config when Spring Security is active on Spring Cloud Config Server 如果配置服务器关闭,Spring Cloud 配置客户端会加载本地属性 - Spring cloud config client load local properties if the config server is down 用于Pivotal实例上受SSL保护的配置服务器的Spring Cloud Config客户端 - Spring cloud config client for SSL protected config server on Pivotal instance spring cloud config客户端未从配置服务器加载配置 - spring cloud config client not loading configuration from config server Spring Cloud Config Server如何将纯文本文件推送到Config Client Application? - How Spring Cloud Config Server PUSH plain text files to Config Client Application? 如何删除Spring Cloud Config Server缓存 - How to remove Spring Cloud Config Server cache 如何保护 Spring Cloud Config Server - How to Secure Spring Cloud Config Server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM