Docker容器通过配置Dockerfile集成Vim

缘起

公司的应用发布软件提供了一键构建docker镜像并部署到k8s集群的功能,确实方便了我们开发的构建和发布,但是有个不好的功能就是日志查看是有限的,只能查看1000行左右的日志,多个测试同学同时调用,日志“唰”一下就没了,然后再回去翻看,发现已经没法回去了,日志收集平台只提供了UAT和生产环境,没有提供给测试环境

解决方案

偶然发现从应用发布软件可以进入docker容器内部,然后我去查看了一下日志的路径,发现日志是存在于配置的路径下的,于是有了一个大胆的想法:装一个vim,想怎么看日志就怎么看日志。
先贴出Dockerfile增加的内容,再细说遇到的问题:

RUN echo 'deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse \n\
           deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse \n\
           deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse \n\
           deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse \n\
           deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse \n\
           deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse \n\
           deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse \n\
           deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse \n\
           deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse \n\
           deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse \n'\
              > /etc/apt/sources.list
RUN ["apt-get", "update"]
RUN ["apt-get","install","vim","-y","--allow-unauthenticated"]

问题

  1. 遇到的第一个问题是

    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    E: Unable to locate package vim
    

    这个问题网上有答案,需要先执行apt update

  2. 第二个问题是执行apt update的时候,由于源是国外的源,更新时间超过6分钟,被健康检查kill掉了,鉴于此,换源,于是有了上面贴出的换阿里云源的命令

  3. 本以为这样没有问题了,然后又遇到一个新问题

    There were unauthenticated packages and -y was used without --allow-unauthenticated
    

    也没去深究背后的原因,大致意思是没有权限,没有--allow-unauthenticated授权,然后加上这个授权,问题解决

至此,问题全部解决,可以愉快的使用vim查看和追踪日志了

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值