解决ubuntu容器缺少vim,且无法apt-get update问题,亲测可用

1.在宿主机上新建sources.list,拷贝到容器:

 

在宿主机新建 sources.list,内容如下(阿里的apt源)

docker cp sources.list  目标容器:/etc/apt

deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse

deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse

deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse

deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse

## Not recommended
# deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

2.在容器内运行apt-get update

如果有报错如下:

Err:1 http://mirrors.ustc.edu.cn/ubuntu xenial InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY **** NO_PUBKEY ****

Reading package lists... Done
W: GPG error: http://mirrors.ustc.edu.cn/ubuntu xenial InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY **** NO_PUBKEY ****
E: The repository 'http://mirrors.ustc.edu.cn/ubuntu xenial InRelease' is not signed.

 

解决办法:等待1分钟

将公钥添加至服务器,即终端中输入

apt-key adv --keyserver keyserver.ubuntu.com --recv-keys '公钥编码'

添加成功后终端输出为

gpg: key '公钥编码': public key "xxxxxx" imported

gpg: Total number processed: 1

gpg:                        imported: 1

 

然后运行apt-get update

 

3.最后 apt-get intsall vim 可用

 

 

 

你可能感兴趣的:(服务器docker化部署,docker,ubuntu)