百分百源码网-让建站变得如此简单! 登录 注册 签到领金币!

主页 | 如何升级VIP | TAG标签

当前位置: 主页>网站教程>服务器> CentOS 7 安装 Docker 应用容器教程
分享文章到:

CentOS 7 安装 Docker 应用容器教程

发布时间:01/15 来源: 浏览: 关键词:
Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,容器就像是轻量级的虚拟机。

本文我们来看看如何在 CentOS 7 上安装 Docker。Docker就像是轻量级的虚拟机,可以让创建和管理 Linux 容器变得简单。并且可以以毫秒级的速度来启动或停止。Docker 帮助系统管理员和程序员在容器中开发应用程序,并且可以扩展到成千上万的节点。

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

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


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

  CentOS 7 中 Docker 的安装

  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 镜像到本地 (LCTT 译注:由于 Docker 被墙 :-< ,所以请使用 http://docker.cn  的镜像,感谢 @马全一 的镜像。 )

[root@localhost ~]# docker pull centos
Pulling repository centos
192178b11d36: Download complete
70441cac1ed5: Download complete
ae0c2d0bdc10: Download complete
511136ea3c5a: Download complete
5b12ef8fd570: Download complete

  确认 CentOS 镜像已经被获取:

[root@localhost ~]# docker images centos
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos centos5 192178b11d36 2 weeks ago 466.9 MB
centos centos6 70441cac1ed5 2 weeks ago 215.8 MB
centos centos7 ae0c2d0bdc10 2 weeks ago 224 MB
centos 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 /<span style="width: auto; height: auto; float: none;" id="0_nwp"><a style="text-decoration: none;" mpid="0" target="_blank" href="http://cpro.baidu.com/cpro/ui/uijs.php?c=news&cf=1001&ch=0&di=128&fv=15&jk=3f02a9bcc6ed33e5&k=etc&k0=etc&kdi0=0&luki=2&n=10&p=baidu&q=06011078_cpr&rb=0&rs=1&seller_id=1&sid=e533edc6bca9023f&ssp2=1&stid=0&t=tpclicked3_hc&tu=u1922429&u=http%3A%2F%2Fwww%2Eadmin10000%2Ecom%2Fdocument%2F5556%2Ehtml&urlid=0" id="0_nwl"><span style="color:#0000ff;font-size:14px;width:auto;height:auto;float:none;">etc</span></a></span>/redhat-release
CentOS Linux release 7.0.1406 (Core)
[root@cd05639b3f5c /]# exit
exit
[root@localhost ~]#

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

[root@localhost ~]# docker search ubuntu
[root@localhost ~]# docker search fedora

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

打赏

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

百分百源码网 建议打赏1~10元,土豪随意,感谢您的阅读!

共有7人阅读,期待你的评论!发表评论
昵称: 网址: 验证码: 点击我更换图片
最新评论

本文标签

广告赞助

能出一分力是一分吧!

订阅获得更多模板

本文标签

广告赞助

订阅获得更多模板