加入收藏 | 设为首页 | 会员中心 | 我要投稿 吉安站长网 (https://www.0796zz.com/)- 物联设备、建站、物联安全、云计算、基础存储!
当前位置: 首页 > 综合聚焦 > CentOS > 正文

CentOS 7 上安装 Docker 详解

发布时间:2023-12-20 01:25:40 所属栏目:CentOS 来源:DaWei
导读: CentOS 中 Docker 的安装
Docker 软件包已经包括在默认的 CentOS-Extras 软件源里。因此想要安装 docker,只需要运行下面的 yum 命令:
CentOS6.8
[root@localhost~]#yum install htt

CentOS 中 Docker 的安装

Docker 软件包已经包括在默认的 CentOS-Extras 软件源里。因此想要安装 docker,只需要运行下面的 yum 命令:

CentOS6.8

[root@localhost~]#yum install http://mirrors.yun-idc.com/epel/6/i386/epel-release-6-8.noarch.rpm

[root@localhost~]#yum install docker-io

CentOS 7

[root@localhost~]#yum install docker-io 启动 Docker 服务

安装完成后,使用下面的命令来启动 docker 服务,并将其设置为开机启动:

[root@localhost~]#service docker start [root@localhost~]#chkconfig docker on

(LCTT 译注:此处采用了旧式的 sysv 语法,如采用CentOS 7中支持的新式 systemd 语法,如下:

[root@localhost~]#systemctl start docker.service [root@localhost~]#systemctl enable docker.service

下载官方的 CentOS 镜像到本地(LCTT 译注:由于 Docker 被墙:-< ,所以请使用http://docker.cn的镜像,感谢@马全一的镜像。 )

[root@localhost~]#docker pull centos Pullingrepository centos 192178b11d36:Downloadcomplete 70441cac1ed5:Downloadcomplete ae0c2d0bdc10:Downloadcomplete 511136ea3c5a:Downloadcomplete 5b12ef8fd570:Downloadcomplete

确认 CentOS 镜像已经被获取:

[root@localhost~]#docker images centos REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE centos centos5192178b11d362weeks ago466.9MB centos centos670441cac1ed52weeks ago215.8MB centos centos7 ae0c2d0bdc102weeks ago224MB centos latest ae0c2d0bdc102weeks ago224MB

运行一个 Docker 容器:

[root@localhost~]#docker run-i-t centos/bin/bash [root@dbf66395436d/]#

我们可以看到,CentOS 容器已经被启动,并且我们得到了 bash 提示符。在 docker 命令中我们使用了 “-i 捕获标准输入输出”和 “-t 分配一个终端或控制台”选项。若要断开与容器的连接,输入 exit。

[root@cd05639b3f5c/]#cat/etc/RedHat-release CentOSLinuxrelease7.0.1406(Core) [root@cd05639b3f5c/]#exit exit [root@localhost~]#

(编辑:吉安站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章