1. 程式人生 > 實用技巧 >docker中使用阿里雲的apt源安裝各種實用工具

docker中使用阿里雲的apt源安裝各種實用工具

今天想在docker中安裝vim工具,還有其他的軟體等等,如果你直接執行apt-get install vim是沒有用的,會顯示:

root@7d43d83fd3a8:/etc/nginx# apt-get install vim
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package vim

看樣子是不可以安裝的,我們需要做的就是修改apt的源即可,再update一下就可以安裝了。

看到網上很多部落格中講解安裝vim工具的時候修改為國內的163的apt源,這裡我不是很推薦,因為我嘗試以後發現有些工具安裝不上去,甚至是連依賴庫和包等等都不能自動解決,那怎麼行呢?所以我索性換為阿里雲的apt源。

步驟如下:

1、更新為最近的阿里雲的apt源,目的是快速更近的更新系統的包等資源。

先備份一下原來的apt源

mv /etc/apt/sources.list /etc/apt/sources.list.bak

更改為阿里雲的源步驟如下:

cat > /etc/apt/sources.list << EOF
deb http://mirrors.aliyun.com/debian/ stretch main non-free contrib deb-src http://mirrors.aliyun.com/debian/ stretch main non-free contrib deb http://mirrors.aliyun.com/debian-security stretch/updates main deb-src http://mirrors.aliyun.com/debian-security stretch/updates main deb http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib deb-src http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib deb http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib deb-src http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib
EOF

因為docker中沒有預設的編輯工具,很是費事,因此建議在容器中先按照這個步驟把vim工具按照一下即可。

2、修改好之後就可以使用update命令同步 /etc/apt/sources.list 和 /etc/apt/sources.list.d 中列出的源索引,獲取最新軟體包

apt-get update

3、即可下載vim、wget、git工具了,非常快速方便

apt-get install vim wget git