遇到docker容器中不能使用 apt-get update无法更新的问题;无法安装vim命令
首先使用命令查找宿主机的DNS server,命令:
nmcli dev show | grep 'IP4.DNS'
然后宿主机中create一个文件,使用命令:
vim /etc/docker/daemon.json
编辑信息:
{
"dns": ["192.168.23.2","8.8.8.8"]
}
备注: 以上dns的ip使用宿主机中查询出来的ip
重启Docker服务,命令:
sudo service docker restart
以上就是在Docker中解决ubuntu中apt-get update使用的方法。
------------------------------------------------------------------------------------------------------------
以上更新完成后开始安装vim命令;
使用命令:
apt-get install -y vim
---------------------------------------------------------------------------------------------------------------
安装完成后开始安装nginx 发现还是安装失败;于是更换docker容器内部的镜像源;
找到srouce.list 文件,使用命令:
进入apt目录:
cd /etc/apt/
备份原镜像源命令:
cp sources.list sources.listbak
修改镜像源内容为阿里源;
vim sources.list
删除全部内容命令:
:.,$d
将阿里源复制粘贴到sources.list文件中,阿里源如下:
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse
保存退出;
更新命令:
apt-get update
----------------------------------------------------------------------------------
再次下载nginx命令:
apt-get install -y nginx
发现下载速度明显提升
下载完毕后,查看下载是否成功:
whereis nginx
出现: nginx: /usr/sbin/nginx /etc/nginx /usr/share/nginx
说明安装成功;
启动nginx命令:
nginx
查看nginx是否启动成功命令:
ps -ef|grep nginx