美文网首页
docker构建prometheus镜像

docker构建prometheus镜像

作者: webxiaohua | 来源:发表于2020-04-28 22:48 被阅读0次

prometheus开源项目的github地址:https://github.com/prometheus/prometheus/

1.准备工作

首先准备母镜像,官方推荐使用busybox,我们本地拉一个下来:

docker pull busybox

然后下载编译好的包,下载地址
下载后解压,然后准备工作目录,目录结构如下:

image.png
2.进入工作目录,准备配置环境

编辑Dockerfile文件:

FROM busybox:latest
LABEL maintainer="webxiaohua@163.com"

COPY package/prometheus        /bin/prometheus
COPY package/promtool          /bin/promtool
COPY package/prometheus.yml  /etc/prometheus/prometheus.yml
COPY package/console_libraries/                     /usr/share/prometheus/console_libraries/
COPY package/consoles/                              /usr/share/prometheus/consoles/
COPY package/LICENSE                                /LICENSE
COPY package/NOTICE                                 /NOTICE

RUN mkdir -p /prometheus && \
    chown -R nobody:nogroup etc/prometheus /prometheus

USER       nobody
EXPOSE     9090
VOLUME     [ "/prometheus" ]
WORKDIR    /prometheus
ENTRYPOINT [ "/bin/prometheus" ]
CMD        [ "--config.file=/etc/prometheus/prometheus.yml", \
             "--storage.tsdb.path=/prometheus", \
             "--web.console.libraries=/usr/share/prometheus/console_libraries", \
             "--web.console.templates=/usr/share/prometheus/consoles" ]

文件编写完成以后,我们开构建镜像:

docker build -t prometheus:2.18 .

一切OK,我们已经看到一个构建好的镜像在我们的仓库当中了。

3.启动prometheus
docker run -d -i -t -p 9090:9090 -v /etc/localtime:/etc/localtime:ro --name prometheus prometheus:2.18

也可以通过docker-compose来启动,docker-compose.yml文件内容:

version: '2.0'
services:
  prometheus:
    image: prometheus:2.18
    container_name: prometheus
    tty: true
    ports:
      - "9090:9090"
    volumes:
      - /etc/localtime:/etc/localtime:ro

启动完成以后就可以通过客户端访问看效果了:


image.png

以上就是简单的镜像构建流程,有问题欢迎留言探讨~

相关文章

网友评论

      本文标题:docker构建prometheus镜像

      本文链接:https://www.haomeiwen.com/subject/dvviwhtx.html