在Docker中使用Spring Boot Actuator? [英] Use Spring Boot Actuator in Docker?

查看:95
本文介绍了在Docker中使用Spring Boot Actuator?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有自定义Spring Boot Acturators的Spring Boot微服务.当我直接运行Jar时,我可以访问所有的执行器,而当我在Docker-Image中运行相同的Jar时,会出现404错误.

I have got a Spring Boot Microservice with custom Spring Boot Acturators. When i run the Jar directly i can access all of my Acturators, when i run the same Jar inside a Docker-Image i get a 404 Error.

SecurityConfig:

SecurityConfig:

@Configuration
public class ActuatorSecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .requestMatcher(EndpointRequest.toAnyEndpoint())
                .anonymous()
                //.authorizeRequests()
                //.anyRequest().authenticated()
                .and()
                .httpBasic();
    }
}

Application.yaml:

Application.yaml:

spring:
    profiles: actuator
management.endpoints:
    web.exposure.include: "*"
    health.show-details: always

这就像样板代码"我的执行者:

This is like the "Boilerplate-Code" of my Acturators:

@Component
@RestControllerEndpoint(id = "acturatorName")
public class acturatorNameActurator {
    @GetMapping(value = "/foo", produces = "application/json")
    public String bar(){
        return "{\"status\":\"started\"}";
    }
    ...
}

当我只运行Jar内运行docker时,我的自定义执行器都没有起作用吗?例如,/actuator/info 起作用,而/actuator/metrics 则不起作用.我该怎么做才能解决此问题?进阶输入

None of my Custom Acturators that work when i just run the Jar run Inside docker? /actuator/info Does work for example but /actuator/metrics doesnt. What can i do to fix this? Ty in advanced

  • 也许我的SecurityConfiguration错误?Spring是否可能因为容器位于另一个(Docker)网络中而阻止了该请求?但是然后我会得到一些不同于404的东西吗?

  • Is maybe my SecurityConfiguration wrong? Does Spring maybe block the Request because the Container is in another (Docker) Network? But then i would get something different then 404 right?

弹簧绑定在IP 0.0.0.0 端口8080上,我可以正常访问我的REST端点

Spring is Bind on IP 0.0.0.0 Port 8080, i can access my REST-Endpoints normally

推荐答案

TL; DR

我忘记更改/添加执行器弹簧轮廓

TL;DR

i forgot to change/add the actuator spring profile

问题出在我的Dockerfile内部:

The problem was inside my Dockerfile:

FROM openjdk:8-jdk-alpine

ADD target/app.jar /jar/

VOLUME /tmp

EXPOSE 8080

ENV SPRINGPROFILES=prod

CMD ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "-Dserver.port=8080", "-Dserver.address=0.0.0.0", "/jar/app.jar", "--spring.profiles.active=${SPRINGPROFILES}"]

  1. 我忘了传递SPRINGPROFILE变量(= prod,actuator)
  2. 它无法识别该变量

在我将dockerfile更改为

after i changed the dockerfile to

FROM openjdk:8-jdk-alpine

ADD target/app.jar /jar/

VOLUME /tmp

EXPOSE 8080

ENV SPRINGPROFILES=prod

ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom","-Dspring.profiles.active=${SPRINGPROFILES}","-jar", "-Dserver.port=8080", "-Dserver.address=0.0.0.0", "/jar/app.jar"]

并将env变量添加到它起作用的docker-compose-file

and adding the env variable to my docker-compose-file it worked

environment:
          - "SPRINGPROFILES=prod,actuator"

这篇关于在Docker中使用Spring Boot Actuator?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆