一、卸载旧版Docker
1、查询是否安装过旧版
- yum list installed | grep docker
复制代码 没有出现内容就表现没有安装过docker
出现以下内容代表安装过docker,若需要安装最新版则进行卸载
2、查询Docker状态,现在是运行状态
- systemctl status docker
- #查询docker状态
复制代码 当前docker正在运行需要停止后再进行卸载
- systemctl stop docker
- #停止docker
复制代码 停止docker服务后,出现以下警告信息,docker在关闭状态下被访问会触发自动唤醒机制,下次再实行任意的docker下令会直接启动docker服务
再次查询docker状态为停止状态
3、删除安装过Docker的相干包
- #删除命令如下
- yum -y remove containerd.io.x86_64 \ docker-buildx-plugin.x86_64 \ docker-ce.x86_64 \ docker-ce-cli.x86_64 \ docker-ce-rootless-extras.x86_64 \ docker-compose-plugin.x86_64
复制代码
- #删除docker相关软件包
- yum remove -y docker*
复制代码
4、删除Docker相干的镜像和容器
docker相干的镜像和容器,在 /var/lib 下
- rm -rf /var/lib/docker #删除/var/lib下的docker文件夹
复制代码 运行后再次查询已经没有docker文件夹了
二、安装Docker
1、安装yum-utils工具包并设置阿里云镜像
- #安装yum-utils工具
- yum install -y yum-utils device-mapper-persistent-data lvm2
复制代码
如果安装yum-utils工具时表现以下内容时,分析安装失败,国外镜像源封锁增强,需要更换国内镜像源后才能安装 点击更改镜像源
- Loading mirror speeds from cached hostfile
- Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
- 14: curl#6 - "Could not resolve host: mirrorlist.centos.org; 未知的错误"
- One of the configured repositories failed (未知),
- and yum doesn't have enough cached data to continue. At this point the only
- safe thing yum can do is fail. There are a few ways to work "fix" this:
- 1. Contact the upstream for the repository and get them to fix the problem.
- 2. Reconfigure the baseurl/etc. for the repository, to point to a working
- upstream. This is most often useful if you are using a newer
- distribution release than is supported by the repository (and the
- packages for the previous distribution release still work).
- 3. Run the command with the repository temporarily disabled
- yum --disablerepo=<repoid> ...
- 4. Disable the repository permanently, so yum won't use it by default. Yum
- will then just ignore the repository until you permanently enable it
- again or use --enablerepo for temporary usage:
- yum-config-manager --disable <repoid>
- or
- subscription-manager repos --disable=<repoid>
- 5. Configure the failing repository to be skipped, if it is unavailable.
- Note that yum will try to contact the repo. when it runs most commands,
- so will have to try and fail each time (and thus. yum will be be much
- slower). If it is a very temporary problem though, this is often a nice
- compromise:
- yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true
- Cannot find a valid baseurl for repo: base/7/x86_64
复制代码 设置阿里云镜像
- yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
复制代码
2、检察所有Docker版本
- yum list docker-ce --showduplicates | sort -r
复制代码
3、安装指定版本Docker
例如安装26.0.2-1.el7版本
注意版本号只要"3:"背面的那部分
- yum install -y docker-ce-26.0.2-1.el7 docker-ce-cli-26.0.2-1.el7 containerd.io
复制代码 4、安装最新版Docker
- yum install -y docker-ce docker-ce-cli containerd.io
复制代码 在下令行中 --allowerasing 参数允许更换冲突的软件包,可以不加
- yum install -y --allowerasing docker-ce docker-ce-cli containerd.io
复制代码
三、Docker利用前准备
1、启动Docker服务
2、停止Docker服务
停止docker服务后,出现以上警告信息,docker在关闭状态下被访问会触发自动唤醒机制,下次再实行任意的docker下令会直接启动docker服务,如果盼望docker不会触发访问自动唤醒机制,停止docker服务时实行以下下令
- systemctl stop docker
- .socket
复制代码 3、检察Docker服务状态
以下是docker服务运行状态
以下是docker服务停止状态
4、设置Docker服务开机自启动
四、docker-compose安装
1、先到GitHub下载docker-compose
docker-compose下载地址
2、将下载好的文件上传到Linux
将docker-compose文件上传到/usr/local/bin下,并改名为docker-compose
给docker-compose添加可实行权限
- chmod +x /usr/local/bin/docker-compose
复制代码 3、检察版本号
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |