如何在 CentOS 7 上安装 Docker
\u5982\u4f55\u5728 CentOS 7 \u4e0a\u5b89\u88c5 Docker1\u3001\u4f7fyum\u7684CentOS-Extras\u914d\u7f6e\u751f\u6548
\u6587\u4ef6CentOS-Base.repo\u4e2denabled\u7684\u5024\u4ece0\u53d8\u62101
vim /etc/yum.repos.d/CentOS-Base.repo
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
enabled=1 \u2605 \u5024\u4ece0\u53d8\u62101
\u203bDocker is included by default in the CentOS-Extras repository
2\u3001\u6267\u884cyum\u3000\u5b89\u88c5
# yum install docker
3\u3001Docker\u542f\u52a8
# systemctl start docker
CentOS 7 \u4e2d Docker \u7684\u5b89\u88c5
Docker \u8f6f\u4ef6\u5305\u5df2\u7ecf\u5305\u62ec\u5728\u9ed8\u8ba4\u7684 CentOS-Extras \u8f6f\u4ef6\u6e90\u91cc\u3002\u56e0\u6b64\u60f3\u8981\u5b89\u88c5 docker\uff0c\u53ea\u9700\u8981\u8fd0\u884c\u4e0b\u9762\u7684 yum \u547d\u4ee4\uff1a
[root@localhost ~]# yum install docker
\u542f\u52a8 Docker \u670d\u52a1
\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u4f7f\u7528\u4e0b\u9762\u7684\u547d\u4ee4\u6765\u542f\u52a8 docker \u670d\u52a1\uff0c\u5e76\u5c06\u5176\u8bbe\u7f6e\u4e3a\u5f00\u673a\u542f\u52a8\uff1a
[root@localhost ~]# service docker start[root@localhost ~]# chkconfig docker on
\uff08LCTT \u8bd1\u6ce8\uff1a\u6b64\u5904\u91c7\u7528\u4e86\u65e7\u5f0f\u7684 sysv \u8bed\u6cd5\uff0c\u5982\u91c7\u7528CentOS 7\u4e2d\u652f\u6301\u7684\u65b0\u5f0f systemd \u8bed\u6cd5\uff0c\u5982\u4e0b\uff1a
[root@localhost ~]# systemctl start docker.service[root@localhost ~]# systemctl enable docker.service
\uff09
\u4e0b\u8f7d\u5b98\u65b9\u7684 CentOS \u955c\u50cf\u5230\u672c\u5730
[root@localhost ~]# docker pull centosPulling repository centos192178b11d36: Download complete 70441cac1ed5: Download complete ae0c2d0bdc10: Download complete 511136ea3c5a: Download complete 5b12ef8fd570: Download complete
\u786e\u8ba4 CentOS \u955c\u50cf\u5df2\u7ecf\u88ab\u83b7\u53d6\uff1a
[root@localhost ~]# docker images centosREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEcentos centos5 192178b11d36 2 weeks ago 466.9 MBcentos centos6 70441cac1ed5 2 weeks ago 215.8 MBcentos centos7 ae0c2d0bdc10 2 weeks ago 224 MBcentos latest ae0c2d0bdc10 2 weeks ago 224 MB
\u8fd0\u884c\u4e00\u4e2a Docker \u5bb9\u5668\uff1a
[root@localhost ~]# docker run -i -t centos /bin/bash[root@dbf66395436d /]#
\u6211\u4eec\u53ef\u4ee5\u770b\u5230\uff0cCentOS \u5bb9\u5668\u5df2\u7ecf\u88ab\u542f\u52a8\uff0c\u5e76\u4e14\u6211\u4eec\u5f97\u5230\u4e86 bash \u63d0\u793a\u7b26\u3002\u5728 docker \u547d\u4ee4\u4e2d\u6211\u4eec\u4f7f\u7528\u4e86 \u201c-i \u6355\u83b7\u6807\u51c6\u8f93\u5165\u8f93\u51fa\u201d\u548c \u201c-t \u5206\u914d\u4e00\u4e2a\u7ec8\u7aef\u6216\u63a7\u5236\u53f0\u201d\u9009\u9879\u3002\u82e5\u8981\u65ad\u5f00\u4e0e\u5bb9\u5668\u7684\u8fde\u63a5\uff0c\u8f93\u5165 exit\u3002
[root@cd05639b3f5c /]# cat /etc/redhat-release CentOS Linux release 7.0.1406 (Core) [root@cd05639b3f5c /]# exitexit[root@localhost ~]#
\u6211\u4eec\u8fd8\u53ef\u4ee5\u641c\u7d22\u57fa\u4e8e Fedora \u548c Ubuntu \u64cd\u4f5c\u7cfb\u7edf\u7684\u5bb9\u5668\u3002
[root@localhost ~]# docker search ubuntu[root@localhost ~]# docker search fedora
\u663e\u793a\u5f53\u524d\u6b63\u5728\u8fd0\u884c\u5bb9\u5668\u7684\u5217\u8868
Docker 软件包已经包括在默认的 CentOS-Extras 软件源里。因此想要安装 docker,只需要运行下面的 yum 命令:
[root@localhost ~]# yum install docker
启动 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 镜像到本地
[root@localhost ~]# docker pull centosPulling repository centos192178b11d36: Download complete 70441cac1ed5: Download complete ae0c2d0bdc10: Download complete 511136ea3c5a: Download complete 5b12ef8fd570: Download complete
确认 CentOS 镜像已经被获取:
[root@localhost ~]# docker images centosREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEcentos centos5 192178b11d36 2 weeks ago 466.9 MBcentos centos6 70441cac1ed5 2 weeks ago 215.8 MBcentos centos7 ae0c2d0bdc10 2 weeks ago 224 MBcentos latest ae0c2d0bdc10 2 weeks ago 224 MB
运行一个 Docker 容器:
[root@localhost ~]# docker run -i -t centos /bin/bash[root@dbf66395436d /]#
我们可以看到,CentOS 容器已经被启动,并且我们得到了 bash 提示符。在 docker 命令中我们使用了 “-i 捕获标准输入输出”和 “-t 分配一个终端或控制台”选项。若要断开与容器的连接,输入 exit。
[root@cd05639b3f5c /]# cat /etc/redhat-release CentOS Linux release 7.0.1406 (Core) [root@cd05639b3f5c /]# exitexit[root@localhost ~]#
我们还可以搜索基于 Fedora 和 Ubuntu 操作系统的容器。
[root@localhost ~]# docker search ubuntu[root@localhost ~]# docker search fedora
显示当前正在运行容器的列表
扩展阅读:新手s如何开始网调 ... centos7开启network服务 ... centos linux 7 ... 序章 终章 中间叫什么 ... case 23 ... centos7安装lxde桌面 ... centos7 命令行 wifi ... centos7的ip地址 ... centos bond0 ...