为了账号安全,请及时绑定邮箱和手机立即绑定

在 docker 容器内安装 vim 问题记录

标签:
Linux Docker

故事的开始

很多互联网公司, 业务走过 0-1 的野蛮生长之后必定需要精细化管理; 尤其是 面向自己用户 这一块, 你需要像个渣男一样了解你的用户特点 / 需要 / 才知道怎样哄人家开心; 人家才会死心塌地跟着你.

如果是 面向企业(to B)用户, 问题很简单: 去拜访不同的合作公司/业内翘楚, 大家都是带有目的性, 互惠互利一来二去就清楚了;

但像我们这种 面向用户(to C) 用户, 如果随机抽样用户邀请到公司;问券调查;且不说一次性, 抽样用户数据是否具有代表性? 用户提出的问题是否是团队的目前发展方向?

所以最近的工作在原有业务分析上再加一层: 用户标签. 标记用户在你应用中行为, 分析用户特点, 使用习惯

中间过程中需要大数据, 所以自己做测试开发选择使用 docker 搭建环境, 中间遇到安装 vim 问题记录

装个 vim 编辑 hadoop-hive.env

在 centos 7 上使用 docker 安装 hive 镜像

$ docker ps
CONTAINER ID   IMAGE                                                  COMMAND                  PORTS                                                      NAMES
dc387ff5c56d   bde2020/hive:2.1.0-postgresql-metastore                "entrypoint.sh /bin/…"   0.0.0.0:10000->10000/tcp, 10002/tcp                        hive-server

$ docker exec -it dc387ff5c56d /bin/bash

# vim 编辑 hadoop-hive.env
/opt# vi hadoop-hive.env
bash: vi: command not found

# 镜像讲究纯净可以理解, 编译安装吧
/opt# yum install vim
bash: yum: command not found
/opt# rpm
bash: rpm: command not found

# 还是 curl 靠得住
/opt# wget http://yum.baseurl.org/download/3.2/yum-3.2.28.tar.gz
bash: wget: command not found
/opt# rz
bash: rz: command not found

/opt# curl
curl: try 'curl --help' or 'curl --manual' for more information
/opt# curl -o yum-3.2.28.tar.gz http://yum.baseurl.org/download/3.2/yum-3.2.28.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  864k  100  864k    0     0   276k      0  0:00:03  0:00:03 --:--:--  667k

# 你也纯净得太过分了吧
/opt# tar -zxvf yum-3.2.28.tar.gz
/opt/yum-3.2.28# ls
AUTHORS  ChangeLog  INSTALL   PLUGINS  TODO  callback.py  docs	output.py  rpmUtils  test      yum		yum.spec	yummain.py
COPYING  FAQ	    Makefile  README   bin   cli.py	  etc	po	   shell.py  utils.py  yum-updatesd.py	yumcommands.py

/opt/yum-3.2.28# make
bash: make: command not found

这时~ bash: make: command not found 嗯? 连个 make 编译命令都没有. 现在容器都 玩得都这么野 的了吗

大意了没有闪, 居然是 debian

不对, 会不会镜像不是 centos 7 的

# 查看 linux 内核版本
/opt/yum-3.2.28# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 7 (wheezy)"
NAME="Debian GNU/Linux"
VERSION_ID="7"
VERSION="7 (wheezy)"
ID=debian
ANSI_COLOR="1;31"
HOME_URL="http://www.debian.org/"
SUPPORT_URL="http://www.debian.org/support/"
BUG_REPORT_URL="http://bugs.debian.org/"

PRETTY_NAME="Debian GNU/Linux 7 (wheezy)" 哟西好家伙, 居然是 debian. 让我查查 apt-get 安装命令

/opt/yum-3.2.28# apt-get install vim
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: 

我就知道事情并不简单
Unable to locate package vim 国内通常是因为 Debian 使用的 apt-get 源在国外需要翻墙导致. 配置国内镜像就好

# 将原 `apt-get`源文件备份, 再配置
/# mv /etc/apt/sources.list /etc/apt/sources.list.bak
deb http://mirrors.163.com/debian/ jessie main non-free contrib
/opt/yum-3.2.28# echo "deb http://mirrors.163.com/debian/ jessie main non-free contrib" >/etc/apt/sources.list

/opt/yum-3.2.28# echo "deb http://mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib" >>/etc/apt/sources.list

/opt/yum-3.2.28# echo "deb-src http://mirrors.163.com/debian/ jessie main non-free contrib" >>/etc/apt/sources.list

/opt/yum-3.2.28# echo "deb-src http://mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib" >>/etc/apt/sources.list

# 更新 apt-get, 安装 vim
/opt/yum-3.2.28# apt-get update
/opt/yum-3.2.28# apt-get install vim

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  libc6 vim-common vim-runtime
Suggested packages:
  glibc-doc locales ctags vim-doc vim-scripts
The following NEW packages will be installed:
  vim vim-common vim-runtime
The following packages will be upgraded:
  libc6
1 upgraded, 3 newly installed, 0 to remove and 179 not upgraded.
Need to get 10.8 MB of archives.
After this operation, 29.6 MB of additional disk space will be used.
Do you want to continue [Y/n]? y

其他方法

除此之外, 如果只是简单的 配置文件替换. 还能通过在宿主机 编辑好 hadoop-hive.env 配置文件, docker cp hadoop-hive.env dc387ff5c56d:/opt 复制到容器指定文件夹下.

总结

安装 docker 镜像是需要留意系统版本内核; 搞错版本 / 版本号和 docker 不匹配容器出现问题

点击查看更多内容
1人点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
全栈工程师
手记
粉丝
154
获赞与收藏
1426

关注作者,订阅最新文章

阅读免费教程

感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消