启动的docker容器镜像里默认是不支持yum命令的,因为里面没有装这些东西,但又是我们经常需要的。因为基本的vim命令都报:vim: command not found,安装如下:本文地址:http://www.04007.cn/article/1008.html,未经许可,不得转载.
root@1a321db343bf:/app# vim conf.py bash: vim: command not found #docker 容器中安装yum命令 apt-get update ##跟新 apt install vim apt install wget apt install yum #ping and ifconfig apt install iputils-ping apt install net-tools本文地址:http://www.04007.cn/article/1008.html,未经许可,不得转载.
安装完成yum,但此时并不能使用yum,因为没有配置任何yum源。运行的时候会报There are no enabled repos。使用yum repolist all可以查看到当前的yum repo列表为空,即repolist为0。可将宿主机的文件复制到容器里。本文地址:http://www.04007.cn/article/1008.html,未经许可,不得转载.
root@1a321db343bf:/app# yum install vim There are no enabled repos. Run "yum repolist all" to see the repos you have. You can enable repos with yum-config-manager --enable <repo> root@1a321db343bf:/app# yum repolist all repolist: 0 #将宿主机的文件复制到容器里yum update [root@test123 ~]# docker cp /etc/yum.repos.d/CentOS.repo 03a90bfeaaf3:/etc/yum/repos.d root@1a321db343bf:/etc/yum/repos.d# yum update CentOS CentOS/primary_db Setting up Update Process No Packages marked for Update本文地址:http://www.04007.cn/article/1008.html,未经许可,不得转载.
然后就可以开始使用yum 安装了吗?还是行的。会报错误GPG key retrieval failed: [Errno 14] curl#37 - "Couldn't open file /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7"。容器里还缺少这个repo对应的key文件,从宿主机中相同的目录下copy过来。本文地址:http://www.04007.cn/article/1008.html,未经许可,不得转载.
#开始使用yum 安装?NO。 root@1a321db343bf:~# yum install vim Setting up Install Process ... GPG key retrieval failed: [Errno 14] curl#37 - "Couldn't open file /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7" root@1a321db343bf:~# ls -al /etc/pki/ ls: cannot access '/etc/pki/': No such file or directory root@1a321db343bf:~# mkdir -p /etc/pki/rpm-gpg [root@test123 ~]# ll /etc/pki/rpm-gpg RPM-GPG-KEY-CentOS-7 RPM-GPG-KEY-CentOS-Debug-7 RPM-GPG-KEY-CentOS-Testing-7 [root@test123 ~]# docker cp /etc/pki/rpm-gpg/* 03a90bfeaaf3:/etc/pki/rpm-gpg/本文地址:http://www.04007.cn/article/1008.html,未经许可,不得转载.
然后就可以在容器里操作yum安装软件了。本文地址:http://www.04007.cn/article/1008.html,未经许可,不得转载.
本文地址:http://www.04007.cn/article/1008.html 未经许可,不得转载. 手机访问本页请扫描右下方二维码.
![]() |
![]() |
手机扫码直接打开本页面 |