小知识:Docker环境缺少vi命令,如何解决

2021-11-30 17:00:33 浏览数 (2)

docker exec可以使用--user参数指定root用户,进入安装vi即可:

代码语言:javascript复制
[opc@oci-001 ~]$ docker exec -it --user root testdb bash
bash-4.2# vi
bash: vi: command not found
bash-4.2# yum install vi
Loaded plugins: ovl
ol7_UEKR5                                                                                                                                                    | 3.0 kB  00:00:00
ol7_latest                                                                                                                                                   | 3.6 kB  00:00:00
(1/5): ol7_UEKR5/x86_64/updateinfo                                                                                                                           | 186 kB  00:00:00
(2/5): ol7_latest/x86_64/group_gz                                                                                                                            | 136 kB  00:00:00
(3/5): ol7_latest/x86_64/updateinfo                                                                                                                          | 3.4 MB  00:00:00
(4/5): ol7_UEKR5/x86_64/primary_db                                                                                                                           |  34 MB  00:00:01
(5/5): ol7_latest/x86_64/primary_db                                                                                                                          |  37 MB  00:00:01
Resolving Dependencies
--> Running transaction check
---> Package vim-minimal.x86_64 2:7.4.629-8.0.1.el7_9 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================================================================================
 Package                                   Arch                                 Version                                              Repository                                Size
====================================================================================================================================================================================
Installing:
 vim-minimal                               x86_64                               2:7.4.629-8.0.1.el7_9                                ol7_latest                               443 k

Transaction Summary
====================================================================================================================================================================================
Install  1 Package

Total download size: 443 k
Installed size: 914 k
Is this ok [y/d/N]: y
Downloading packages:
vim-minimal-7.4.629-8.0.1.el7_9.x86_64.rpm                                                                                                                   | 443 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 2:vim-minimal-7.4.629-8.0.1.el7_9.x86_64                                                                                                                         1/1
  Verifying  : 2:vim-minimal-7.4.629-8.0.1.el7_9.x86_64                                                                                                                         1/1

Installed:
  vim-minimal.x86_64 2:7.4.629-8.0.1.el7_9

Complete!
bash-4.2# vi
bash-4.2#

0 人点赞