文章目录
有一个Centos7的虚拟机,想要安装个docker测试一些docker用法和熟悉命令
一,准备工作
1,使用uname -r命令检查系统内核版本,只有大于3.10才建议安装Docker
2,使用yum update命令更新系统
如果该命令执行报错,类似cannot find a valid baseurl for repo:base/7/x86_64
那就需要更改仓库配置文件了,位置路径如下所示
/etc/yum.repos.d/CentOS-Base.repo
文件完整内容如下,采用了阿里云镜像
# CentOS-Base.repo # # The mirror system uses the connecting IP address of the client and the # update status of each mirror to pick mirrors that are updated to and # geographically close to the client. You should use this for CentOS updates # unless you are manually picking other mirrors. # # If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead. # # [base]name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#released updates [updates]name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful [extras]name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
gpgcheck=1gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages [centosplus]name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1enabled=0gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#contrib - packages by Centos Users [contrib]name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
gpgcheck=1enabled=0gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
PS:在CentOS环境的Vi编辑器一般模式下,按下yy(yank yank的缩写,意为复制),按下nyy(n为你想要复制的行数),按下p键,复制的文本将被粘贴到光标所在行的下一行。按v进入可视模式,按i进入编辑模式
二、安装Docker
1,安装必要软件包,三个Docker运行所需的依赖包
sudo yum install-y yum-utils device-mapper-persistent-data lvm2
2,设置Docker镜像源,设置成阿里的镜像源是为了加快安装和后续镜像的下载速度
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
3,安装最新版本的Docker CE,这一步可能要耗费一点时间
sudo yum install-y docker-ce docker-ce-cli containerd.io
三、启动Docker
sudo systemctl start docker 启动服务
sudo systemctl status docker 检查 Docker 服务的状态
sudo systemctl enabledocker 开机自启
四、验证Docker
docker-vdocker--version
运行hello-world
sudodocker run hello-world
访问不了docker hub,所以无法运行hello-world,只能运行自己打包的镜像,就是把打包的jar包用docker生成镜像后在运行
五、使用Docker
具体使用参考以前一篇博文 Docker使用心得与技巧
六,卸载Docker
sudo yum remove docker docker-common docker-selinux docker-engine
版权归原作者 xun-ming 所有, 如有侵权,请联系我们删除。