Spring Boot - 执行器指标端点在 docker 映像中不起作用

问题描述

在我的 Spring Boot 应用程序 Yaml 中,我有

 management:
  metrics:
    export:
      simple:
        enabled: true
  endpoints:
    web:
      exposure:
        include: "*"

但是,当我点击

localhost:8080/actuator/metrics 

它在 spring boot 独立应用程序中工作,但在 docker 映像中,端点执行器/指标不起作用,它将我重定向页面,该应用程序仍然可以正常工作。

我的 docker 文件

  FROM openjdk:11-jre-buster

RUN apt update && apt install curl -y \
        && rm -rf /var/lib/apt/lists/*


MAINTAINER  xxxxx
ARG VERSION

ENV SERVER_PORT 80
ENV JAVA_OPTS -Xmx1g

# add this to solve buster sso issue
ENV OPENSSL_CONF=/etc/ssl

ENV SPRINGPROFILES=actuator

workdir /app
copY maven/docker-package/ /app

# Tesseract installation
RUN apt-get install apt-transport-https && \
    echo "deb [trusted=yes] https://notesalexp.org/tesseract-ocr/buster/ buster main" >> /etc/apt/sources.list && \
    apt-get update -oAcquire::AllowInsecureRepositories=true && \
    apt-get install notesalexp-keyring -oAcquire::AllowInsecureRepositories=true && \
    apt-get update && \
    apt-get -y install tesseract-ocr 

EXPOSE ${SERVER_PORT}

HEALTHCHECK --interval=5s --timeout=5s --retries=3 \
      CMD curl -f http://localhost:80/actuator/health || exit 1

ENTRYPOINT ["sh","/app/docker-entrypoint.sh"]

docker-entrypoint.sh :

java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -Dlicense.path=/app/licenses/ "-Dspring.profiles.active=${SPRINGPROFILES}" -Dlogging.config=/app/config/log4j2.xml -Dserver.port=80 -jar /app/app-executable.jar

我错过了什么?是否需要进行任何配置来公开 docker 中的指标?感谢您的回复

解决方法

你应该在运行 docker 时打开端口:

sudo docker run **** 8080/8080 *****
,

您是否添加了 actuator 个人资料:

environment:
      - "SPRINGPROFILES=prod,actuator"

更多信息here

,

复制Config目录下的application.yml并将其设置到我的应用程序的configDir中,然后将其移动到图像中解决了我的问题!