使用CentOS配置Docker

Docker可以运行在Windows上,可以运行在macOS上,当然也可以运行在Linux上。作为Linux的一个知名发行版,CentOS,自然也可以搭载运行Docker。CentOS跟另一个曝光度更高的Ubuntu都是Linux发行版,但是二者不通(悲)。

这篇博客会描述对Ubuntu的操作有了解的读者,如何快速在CentOS上搭建Docker。

yum

熟练用过Ubuntu的读者都知道,安装软件用apt。(我个人觉得用macOS的应该会知道用Homebrew,Windows就难说了)

在CentOS上,包管理工具叫做yum。使用yum安装包依然是用install命令(嗯,你还是逃不过必须sudo的命运)。但是不能直接输入sudo yum install docker来安装,首先你需要引入Docker仓库。

引入Docker仓库

然而,要引入Docker仓库首先需要安装能够修改yum配置的实用程序。运行

sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2

来安装它们。安装过程是静默的,如果想要手动输入那个y来确认的话,去掉上述指令的-y(跟apt很像)。
随后,使用

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

将Docker的repo加入yum当中。

安装Docker

如果你曾经安装过Docker,请先使用下面的命令来卸载它。

sudo yum remove docker \
                docker-client \
                docker-client-latest \
                docker-common \
                docker-latest \
                docker-latest-logrotate \
                docker-logrotate \
                docker-engine

使用下述命令安装Docker。

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

这会安装Docker的社区(免费的!)版本,如果yum询问是否接受GPG钥,检查这个钥之后接受它,就可以了。

Docker作为一个服务,在安装之后需要启动。

sudo systemctl start docker

将会启动Docker服务。

跑一个Hello world吧

输入

sudo docker run hello-world

输出以下内容

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world

这表示在本地没有找到hello-world这个镜像,所以它去Docker网站下载了。Docker维护了一个Hub,存放了常用的镜像,可以拿来即用,十分方便。

下载完毕之后,输出以下内容之后镜像就退出了。

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

安装成功了。我们通过命令行调用了Docker的前端程序,前端程序调用了我们刚刚启动的守护进程,守护进程从互联网上下载了镜像,随后创建了环境(容器)并且运行了镜像。守护进程,即后端,即服务,将镜像的输出串流到了前端输出,所以我们在屏幕上看到了这些。镜像退出之后,容器也随之销毁了。

以上就是在CentOS当中安装并试运行Docker的全部过程。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CentOS配置Docker可以通过以下步骤完成: 1. 首先,您可以使用以下命令将Docker存储库添加到您的系统中: yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo​​​​​​​​​​​ 2. 接下来,您可以使用以下命令安装Docker Engine - Community: yum install docker-ce docker-ce-cli containerd.io 3. 安装完成后,您可以使用以下命令启动Docker服务并将其设置为开机自启动: systemctl start docker systemctl enable docker 4. 如果您希望使用阿里云的服务器作为Docker的镜像源,您可以使用以下命令将阿里云的Docker存储库添加到您的系统中: yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 5. 最后,使用以下命令重启Docker服务以使更改生效: systemctl restart docker 现在,您的CentOS系统已成功配置Docker。您可以使用各种Docker命令来管理和运行容器。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [centos下部署docker](https://blog.csdn.net/m0_61344379/article/details/125332483)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [CentOS7环境下配置Docker](https://blog.csdn.net/chung961977305/article/details/105025644)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值