如何在Linux环境下安装并配置Docker

一、什么是Docker

Docker 是一个开源的容器化平台,用于开发、部署和运行应用程序。它允许你将应用程序及其依赖项打包到一个轻量级、可移植的容器中,确保应用在不同环境中一致运行。

Docker官网:https://www.docker.com
Docker中文库:https://www.docker.org.cn/

 熟悉并经常使用python的同学可能知道,conda为我们提供了虚拟环境,用于隔离 Python 的包依赖,避免版本冲突。同时可将环境配置导出用于移植。这些特性都同Docker有着相似之处。

二、安装Docker

1、安装必要的工具包

yum-untils 工具集,它提供了对 YUM(Yellowdog Updater Modified)包管理器的扩展功能,这些功能在 Docker 的安装过程中非常重要。

sudo yum install -y yum-utils

2、设置Docker仓库

sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

执行上述命令后,查看是否配置成功

cd /etc/yum.repos.d
ls

 看到如图所示红框中的内容,即为配置成功。

3、安装Docker引擎

sudo yum install -y docker-ce docker-ce-cli containerd.io

安装所需时间较长,请耐心等待。

4、启动Docker服务

# 启动 Docker 服务
sudo systemctl start docker
# 设置docker开机自启
sudo systemctl enable docker

5、验证是否安装成功

sudo docker run hello-world

出现如下提示即为安装成功了!!

三、安装过程中遇到的问题

在第一次安装docker引擎时,使用了官方的yum源,遇到了如下报错:


sudo yum install -y docker-ce docker-ce-cli containerd.io 已加载插件:fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com https://download.docker.com/linux/centos/7/x86_64/stable/repodata/repomd.xml: [Errno 14] curl#35 - "TCP connection reset by peer" 正在尝试其它镜像。 One of the configured repositories failed (Docker CE Stable - x86_64), 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=docker-ce-stable ... 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 docker-ce-stable or subscription-manager repos --disable=docker-ce-stable 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=docker-ce-stable.skip_if_unavailable=true failure: repodata/repomd.xml from docker-ce-stable: [Errno 256] No more mirrors to try. https://download.docker.com/linux/centos/7/x86_64/stable/repodata/repomd.xml: [Errno 14] curl#35 - "TCP connection reset by peer"

解决办法

1、切换国内的镜像源

# 先移除之前添加的 Docker 官方仓库
sudo yum-config-manager --remove-repo https://download.docker.com/linux/centos/docker-ce.repo

# 添加阿里云 Docker 镜像仓库
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

# 清理并重建缓存
sudo yum clean all
sudo yum makecache

2、重新尝试安装

sudo yum install -y docker-ce docker-ce-cli containerd.io

3、重启Docker

sudo systemctl daemon-reload
sudo systemctl restart docke

如上就是在Linux下安装Docker的过程了,如有问题欢迎指点学习。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值