如何解决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中,然后将其移动到图像中解决了我的问题!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。