[Zipkin] zipkin-ui修改后单独打成镜像

由于要在zipkin的界面基础上进行修改,所以需要单独打包zipkin-ui并以docker形式跑起来(zipkin后台一直运行着)。一个学长曾经做过,记录如下,亲测可用:

  1. Maven打包zipkin:parent(root) -> package

  2. 把打好的zipkin-ui.jar包放到文件夹zipkin-ui中,里面还要放入三个文件:

  • nginx.conf文件
user  nginx nginx;
worker_processes  2;

error_log  /dev/stderr warn;
pid        /var/run/nginx.pid;

daemon off;

events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /dev/stdout  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    gzip  on;
    gzip_types    application/javascript application/json text/css;

    server_tokens off;

    types {
        application/font-woff2  woff2;
    }

    server {
        listen  9091;

        root /var/www/html;

        index index.html;

        # Make site accessible from http://set-ip-address.xip.io
        server_name localhost;

        charset utf-8;

        # redirect root as UI is hosted under /zipkin
        location / {
          return 302 /zipkin/;
        }

        # the entrypoint of the app will expire every day.
        # this includes links to js assets with random names.
        location /zipkin/index.html {
            expires 1d;
        }

        location /zipkin {
          try_files $uri /zipkin/index.html = 404;
        }

        # accept UI config from the server
        location /zipkin/config.json {
            expires 10m;
            proxy_pass ${ZIPKIN_BASE_URL};
        }

        # the UI looks for the api under the same relative path
        location /zipkin/api {
            expires off;
            proxy_pass ${ZIPKIN_BASE_URL};
        }

        # due to minification, the js assets will change names.
        # this makes them safe to cache longer
        location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
            expires 1y;
            add_header Cache-Control "public";
        }

        location = /favicon.ico { log_not_found off; access_log off; }
        location = /robots.txt  { access_log off; log_not_found off; }

        # Deny .htaccess file access
        location ~ /\.ht {
            deny all;
        }

    }
}
  • run.sh文件
#!/bin/sh
envsubst '\$ZIPKIN_BASE_URL' < /etc/nginx/conf.d/zipkin.conf.template > /etc/nginx/nginx.conf
exec nginx

  • Dockerfile文件
# pins on 1.11 as it is built against Alpine 3.4 which doesn't die with SSL certificate problem
FROM nginx:1.11-alpine

ENV ZIPKIN_VERSION 2.10.1
#!!!!!!change to your zipkin backend ip:port!!!!!!!!!!
ENV ZIPKIN_BASE_URL=http://xxxxx:xxx
#!!!!!!change to your zipkin-ui.jar name!!!!!!!!!!!
COPY zipkin-ui-2.10.1-SNAPSHOT.jar zipkin-ui-2.10.1-SNAPSHOT.jar

# Setup services
ADD nginx.conf /etc/nginx/conf.d/zipkin.conf.template
ADD run.sh /usr/local/bin/nginx.sh

RUN apk add --update --no-cache nginx curl &&
    rm -rf /var/cache/apk/* /tmp/* /var/tmp/* && \
    mkdir /var/www/html && \
    unzip zipkin-ui-2.10.1-SNAPSHOT.jar 'zipkin-ui/*' -d /var/www/html && \
    mv /var/www/html/zipkin-ui /var/www/html/zipkin && \
    rm -rf zipkin-ui-2.10.1-SNAPSHOT.jar && \
    chmod +x /usr/local/bin/nginx.sh

EXPOSE 9091

CMD ["/usr/local/bin/nginx.sh"]

  1. 镜像生成、上传:
#【docker build -t (镜像名) -f (Dockerfile文件的路径) (上下文路径)】
#(最后的点号不要忘记)
docker build -t zipkin-ui -f Dockerfile .
#跑一下试试
docker run -p 9091:9091 zipkin-ui
#打tag、push到docker hub
docker tag zipkin-ui xxx/zipkin-ui
docker push xxx/zipkin-ui
  1. 使用docker-compose跑,可以修改zipkin后台地址:
  • docker-compose.yml
# This file uses the version 2 docker-compose file format, described here:
# https://docs.docker.com/compose/compose-file/#version-2
#
# It extends the default configuration from docker-compose.yml, hosting the
# ui on port 80 using NGINX

version: '2'

services:
  zipkin-ui:
    build: zipkin-ui
    #change to your image uri
    image: xxxx/zipkin-ui
    container_name: zipkin-ui
    environment:
      # Change this if connecting to a different zipkin server
      - ZIPKIN_BASE_URL=http://xxxxx:xxx
    ports:
      - 9091:9091
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值