解决docker中无法使用编辑器vi 或者 vim

  1. 首先你已经进入容器当中
docker exec -it mysql /bin/bash
  1. 错误场景复现
root@6b0e4fb423e0:~/.halo2/themes/theme-dream/templates/common# vim footer.html
bash: vim: command not found
root@6b0e4fb423e0:~/.halo2/themes/theme-dream/templates/common# vi footer.html
bash: vi: command not found
root@6b0e4fb423e0:~/.halo2/themes/theme-dream/templates/common# yum install vim
bash: yum: command not found
root@6b0e4fb423e0:~/.halo2/themes/theme-dream/templates/common# vi
vigr  vipw
  1. 解决办法
  • 先查看下容器里面的操作系统,如上图错误场景中yum命令没有,可能就是Ubuntu系统
root@6b0e4fb423e0:~/# `more /etc/os-release`
PRETTY_NAME="Ubuntu 22.04.2 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.2 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
  • 执行命令,先更新后安装
apt-get update
apt-get install vim