如何在 CentOS 7 上安装 Docker

运维 系统运维 Linux
Docker 的局限性之一是,它只能用在 64 位的操作系统上在这篇文章中我们将讨论如何在 CentOS 7.x 中安装 docker。

Docker 是一个开源工具,它可以让创建和管理 Linux 容器变得简单。容器就像是轻量级的虚拟机,并且可以以毫秒级的速度来启动或停止。Docker 帮助系统管理员和程序员在容器中开发应用程序,并且可以扩展到成千上万的节点。

容器和 VM(虚拟机)的主要区别是,容器提供了基于进程的隔离,而虚拟机提供了资源的完全隔离。虚拟机可能需要一分钟来启动,而容器只需要一秒钟或更短。容器使用宿主操作系统的内核,而虚拟机使用独立的内核。

Docker 的局限性之一是,它只能用在 64 位的操作系统上。

[[123484]]

在这篇文章中我们将讨论如何在 CentOS 7.x 中安装 docker。

CentOS 7 中 Docker 的安装

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

  1. [root@localhost ~]# yum install docker

启动 Docker 服务

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

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

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

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

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

  1. [root@localhost ~]# docker pull centos
  2. Pulling repository centos
  3. 192178b11d36: Download complete
  4. 70441cac1ed5: Download complete
  5. ae0c2d0bdc10: Download complete
  6. 511136ea3c5a: Download complete
  7. 5b12ef8fd570: Download complete

确认 CentOS 镜像已经被获取:

  1. [root@localhost ~]# docker images centos
  2. REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
  3. centos centos5 192178b11d36 2 weeks ago 466.9 MB
  4. centos centos6 70441cac1ed5 2 weeks ago 215.8 MB
  5. centos centos7 ae0c2d0bdc10 2 weeks ago 224 MB
  6. centos latest ae0c2d0bdc10 2 weeks ago 224 MB

运行一个 Docker 容器:

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

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

  1. [root@cd05639b3f5c /]# cat /etc/redhat-release
  2. CentOS Linux release 7.0.1406 (Core)
  3. [root@cd05639b3f5c /]# exit
  4. exit
  5. [root@localhost ~]#

我们还可以搜索基于 Fedora 和 Ubuntu 操作系统的容器。

  1. [root@localhost ~]# docker search ubuntu
  2. [root@localhost ~]# docker search fedora

显示当前正在运行容器的列表


via: http://www.linuxtechi.com/install-docker-on-centos-7/

作者:Pradeep Kumar 译者:felixonmars 校对:wxy

责任编辑:林师授 来源: Linux中国
相关推荐

2017-05-03 14:00:00

LinuxCentOSElastic Sta

2015-09-10 11:38:37

iTOPCentOS开源

2015-12-11 13:16:10

CentOS 7Redis服务器

2015-12-29 13:59:53

Ubuntu 15.0CentOS 7Android Stu

2016-01-06 13:04:13

CentOS 7Ubuntu 15.0Laravel

2017-03-21 15:51:57

LinuxCentOS 7MariaDB 10

2024-01-04 11:50:00

UbuntuDocker

2017-02-16 10:15:43

Windows7docker变量

2017-08-15 11:58:15

LinuxCentOSApache Hado

2011-04-06 09:16:05

2017-06-05 13:02:55

CentOS 7iRedMailSamba4 AD

2014-10-11 11:30:43

CentOSDocker

2020-03-02 14:06:54

CentOS 8FFmpegLinux

2013-04-07 15:14:41

2013-12-04 14:45:22

2017-04-11 13:20:06

CentOSRHELFedora

2015-12-11 09:45:45

CentOSZephyr工具

2019-04-08 09:00:00

CentOS 7ElasticsearLinux

2019-12-02 11:50:09

CentOS 8VirtualBoxLinux

2015-12-21 13:19:23

CentosRHEL 6.XWetty
点赞
收藏

51CTO技术栈公众号