容器内需要编辑文件,但无法下载和使用ed 、vi、vim、nano编辑器

发布于:2024-04-24 ⋅ 阅读:(22) ⋅ 点赞:(0)

报错信息:由于使用的Debian Jessie 已经到达了维护结束的状态,其软件包仓库可能已被归档或移除。并且无法通过apt-get update来更新,或者apt-get install vim下载。

root@1d6f4966854a:/usr/src/app# apt-get update
Ign http://security.debian.org jessie/updates InRelease
Ign http://security.debian.org jessie/updates Release.gpg
Ign http://security.debian.org jessie/updates Release
Ign http://deb.debian.org jessie InRelease
Err http://security.debian.org jessie/updates/main amd64 Packages

Err http://security.debian.org jessie/updates/main amd64 Packages

Ign http://deb.debian.org jessie-updates InRelease
Err http://security.debian.org jessie/updates/main amd64 Packages

Err http://security.debian.org jessie/updates/main amd64 Packages

Err http://security.debian.org jessie/updates/main amd64 Packages
  404  Not Found [IP: 151.101.130.132 80]
Ign http://deb.debian.org jessie Release.gpg
Ign http://deb.debian.org jessie-updates Release.gpg
Ign http://deb.debian.org jessie Release
Ign http://deb.debian.org jessie-updates Release
Err http://deb.debian.org jessie/main amd64 Packages
  404  Not Found
Err http://deb.debian.org jessie-updates/main amd64 Packages
  404  Not Found
W: Failed to fetch http://security.debian.org/dists/jessie/updates/main/binary-amd64/Packages  404  Not Found [IP: 151.101.130.132 80]

W: Failed to fetch http://deb.debian.org/debian/dists/jessie/main/binary-amd64/Packages  404  Not Found

W: Failed to fetch http://deb.debian.org/debian/dists/jessie-updates/main/binary-amd64/Packages  404  Not Found

E: Some index files failed to download. They have been ignored, or old ones used instead.
root@1d6f4966854a:/usr/src/app# apt-get install vim
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package vim is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'vim' has no installation candidate
root@1d6f4966854a:/usr/src/app#

解决办法:

排查之后只有echo才能编辑文本,尝试更新 /etc/apt/sources.list 文件,使用 archive 中的源,而不是原来的旧版本源。这将逐行向 /etc/apt/sources.list 文件添加下面四行内容。

echo "deb http://archive.debian.org/debian/ jessie main" >> /etc/apt/sources.list
echo "deb-src http://archive.debian.org/debian/ jessie main" >> /etc/apt/sources.list
echo "deb http://archive.debian.org/debian-security/ jessie/updates main" >> /etc/apt/sources.list
echo "deb-src http://archive.debian.org/debian-security/ jessie/updates main" >> /etc/apt/sources.list

完成后可以运行 apt-get update 命令以更新软件包列表,并尝试安装 Vim:

apt-get update
apt-get install vim

运行过程中一些软件包已经没办法找到了,但是其他的代码都顺利执行并且结束了运行,即vim能够正常使用了。