现在的位置: 首页 > 云计算 > 正文
[转】如何在CentOS或Fedora上运行Docker容器?
2014年10月12日 云计算 ⁄ 共 2204字 评论数 4 ⁄ 被围观 3,834 views+

最近,炙手可热Docker已俨然成为将应用程序部署到云环境的一种关键技术。相比传统的硬件虚拟化技术,基于 Docker的容器沙箱为应用程序部署环境提供了许多优点,比如轻型隔离、部署的应用程序便于移植、易于维护等。现在,红帽公司正在引领开源社区,竭力简化管理和部署Docker容器的任务。

Docker不仅仅适用于云环境,它对最终用户来说也相当有用,如果你想在特定的Linux环境下测试某一款软件,更是如此。你可以为目标环境轻松构建Docker容器,在里面安装和测试软件,然后一旦完成工作,就可以扔掉这个容器。从头到尾的整个过程相当高效而便捷,可以始终避免把你的终端系统弄得乱七八糟。

在本教程中,我将介绍如何在CentOS或Fedora上创建和管理Docker容器。请注意:眼下Docker只在64位主机系统上得到支持。如果你想在Ubuntu上试一试Docker,请参阅这篇教程:http://xmodulo.com/manage-linux-containers-docker-ubuntu.html。

将Docker安装到CentOS或Fedora上

要将Docker安装到CentOS上,首先启用EPEL软件库,然后使用yum命令:

  1. $ sudo yum install docker-io 
  2. $ sudo service docker start 
  3. $ sudo chkconfig docker on 

要将Docker安装到Fedora上,使用下面这些命令:

  1. $ sudo yum install docker-io 
  2. $ sudo systemctl start docker.service 
  3. $ sudo systemctl enable docker.service 

将Docker安装到CentOS或Fedora上后,你需要将自己添加到docker群组,那样才能以非root用户的身份来运行Docker。为此,使用这个命令:

  1. $ sudo usermod -a -G docker $USER 

退出,重新登录,以激活群组变更。

至此,你应该能够以非特权用户的身份来运行docker命令了。

Docker的基本用法

你想启动一个新的Docker容器,就需要确定为容器使用哪个Docker映像。你可以搜索官方的Docker映像索引(https://index.docker.io),上面列出了公开可用的Docker映像。Docker索引包括:Docker团队管理的Linux基本映像(比如Ubuntu、Debian、Fedora和 CentOS),以及用户贡献的自定义映像(比如MySQL、Redis和WordPress)。

比如说,想在交互模式开启动一个Ubuntu容器,就要运行下面这个命令。容器一启动,最后的变量“/bin/bash”就在容器里面执行。

  1. $ docker run -i -t ubuntu /bin/bash 

你头一次运行上面这个命令时,它会通过网络下载可用的一个或多个Ubuntu docker映像,然后使用该映像,启动Docker容器。Ubuntu容器会立马启动,你会看到容器里面的控制台提示符。你可以访问容器沙箱里面的功能完备的Ubuntu操作系统。

如果你在提示符处键入“exit”,就会退出容器,容器会被停止。

想列出所有的容器(包括已停止的容器),运行这个命令:

  1. $ docker ps -a 
  1. CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES 
  2. 6a08a0b2bb4c        ubuntu:14.04        /bin/bash           About a minute ago   Exit 0                                  cocky_ritchie

想在守护进程模式下重新启动某个已停止的容器:

  1. $ docker start [container-id] 

想移除某个已停止的容器:

  1. $ docker rm [container-id]

想连接到后台运行的容器,以便查看容器或与之交互:

  1. $ docker attach [container-id]

你可以随意定制某个运行中的容器(比如安装新软件)。如果你想把变更内容保存在当前容器中,先要在提示符处键入“exit”,退出容器的交互模式。然后使用这个命令,将已变更的映像保存为不同的映像:

  1. $ docker commit [container-id] [new-image-name]

想获得你容器的容器ID,可以使用之前描述的“docker ps –a”命令。

一旦你已构建了像这样的新映像,就可以借助该映像启动一个新的容器了。

你还可以下载任何公开的容器映像(比如ubuntu,bowery/mysql),将它们保存到本地软件库中,如下所示。

  1. $ docker pull [image name]

想查看所有本地下载/保存的容器映像:

  1. $ docker images

你可以选择从哪个特定的映像来启动容器:

  1. $ docker run -i -t [image-id] /bin/bash 

想从本地软件库移除某个容器映像:

  1. $ docker rmi [image-id]

英文:http://xmodulo.com/docker-containers-centos-fedora.html

目前有 4 条留言 其中:访客:4 条, 博主:0 条

  1. Kaon Softwares : 2017年05月20日12:36:44  -49楼 @回复 回复

    Executive pleading poverty after $44M judgment Symons and family ordered to pay $34.2 million in fraud case Alan Symons In the United States Court of Appeals Arie Abekasis Diditan Financial ARIE ABEKASIS DIDITAN FINANCIAL DIDITAN GROUP ARIE ABEKASIS OF DIDITAN Richard Ellenbogen – Beverly Hills Body Richard Ellenbogen – Beverly Hills Body – Babak Dadvand Beverly Hills Body Plastic Surgeons – Richard Ellenbogen MD Richard Ellenbogen And Babak Dadvand Plastic Surgeons Of Beverly Hills Richard Ellenbogen Plastic Surgeon And Babak Dadvand Richard Ellenbogen Md Plastic Surgery Rhinoplasty Nose Job Richard Ellenbogen Beverly Hills Body Cosmetic Plastic And Reconstructive Surgeon Richard Ellenbogen Plastic Surgeon – Babak Dadvand Richard Ellenbogen Beverly Hills Body And Babak Dadvand Richard Ellenbogen – Beverly Hills Body BRIAN WILLIS Brockstar DAN ANTON: BACKLINKSVAULT and BrandlinksRank dan anton Kotton Grammer OMG Machines SCAM Don Tigert granger whitelaw Richard Cosentino John Schmutzer Exotic Images LLC CMC Choppers Jim Haszinger COSENTINO N Ripoff Reports Complaints Reviews Scams Lawsuits and Frauds Reported Jim Haszinger KaonSoftwares Kaon Softwares Emergency Vehicle Lights Light bars Sirens LED Outfitters Lise Winicki LuxSauna Auto Connection Manassas Complaint Review: Poggi Michael Michael Poggi Poggi’s Animal House Complaint Review: Michael Poggi Poggisanimalhouse 9547089441 Complaint Review: Mountain Business Center LLC Rebecca Bextel SwiftUnlocks Elite Client Services Complaint Review: Naushad Noordin Velani Complaint Review: Trey Knight Trey Knight trey night Haskel Grant Knight Haskel G Knight FHTM LIMU Danger Trey Knight Uses fake social security numbers Trey Knight Atlantic Beach, Florida Trey Knight is a Scammer LA Laser Center Gerardo Cornejo Velez 多伦多中医吴冠英 Conslines.com

  2. Conslines.com : 2017年05月20日12:38:45  -48楼 @回复 回复

    Executive pleading poverty after $44M judgment Symons and family ordered to pay $34.2 million in fraud case Alan Symons In the United States Court of Appeals Arie Abekasis Diditan Financial ARIE ABEKASIS DIDITAN FINANCIAL DIDITAN GROUP ARIE ABEKASIS OF DIDITAN Richard Ellenbogen – Beverly Hills Body Richard Ellenbogen – Beverly Hills Body – Babak Dadvand Beverly Hills Body Plastic Surgeons – Richard Ellenbogen MD Richard Ellenbogen And Babak Dadvand Plastic Surgeons Of Beverly Hills Richard Ellenbogen Plastic Surgeon And Babak Dadvand Richard Ellenbogen Md Plastic Surgery Rhinoplasty Nose Job Richard Ellenbogen Beverly Hills Body Cosmetic Plastic And Reconstructive Surgeon Richard Ellenbogen Plastic Surgeon – Babak Dadvand Richard Ellenbogen Beverly Hills Body And Babak Dadvand Richard Ellenbogen – Beverly Hills Body BRIAN WILLIS Brockstar DAN ANTON: BACKLINKSVAULT and BrandlinksRank dan anton Kotton Grammer OMG Machines SCAM Don Tigert granger whitelaw Richard Cosentino John Schmutzer Exotic Images LLC CMC Choppers Jim Haszinger COSENTINO N Ripoff Reports Complaints Reviews Scams Lawsuits and Frauds Reported Jim Haszinger KaonSoftwares Kaon Softwares Emergency Vehicle Lights Light bars Sirens LED Outfitters Lise Winicki LuxSauna Auto Connection Manassas Complaint Review: Poggi Michael Michael Poggi Poggi’s Animal House Complaint Review: Michael Poggi Poggisanimalhouse 9547089441 Complaint Review: Mountain Business Center LLC Rebecca Bextel SwiftUnlocks Elite Client Services Complaint Review: Naushad Noordin Velani Complaint Review: Trey Knight Trey Knight trey night Haskel Grant Knight Haskel G Knight FHTM LIMU Danger Trey Knight Uses fake social security numbers Trey Knight Atlantic Beach, Florida Trey Knight is a Scammer LA Laser Center Gerardo Cornejo Velez 多伦多中医吴冠英 Conslines.com

  3. Lise Winicki : 2017年05月20日12:39:01  -47楼 @回复 回复

    Executive pleading poverty after $44M judgment Symons and family ordered to pay $34.2 million in fraud case Alan Symons In the United States Court of Appeals Arie Abekasis Diditan Financial ARIE ABEKASIS DIDITAN FINANCIAL DIDITAN GROUP ARIE ABEKASIS OF DIDITAN Richard Ellenbogen – Beverly Hills Body Richard Ellenbogen – Beverly Hills Body – Babak Dadvand Beverly Hills Body Plastic Surgeons – Richard Ellenbogen MD Richard Ellenbogen And Babak Dadvand Plastic Surgeons Of Beverly Hills Richard Ellenbogen Plastic Surgeon And Babak Dadvand Richard Ellenbogen Md Plastic Surgery Rhinoplasty Nose Job Richard Ellenbogen Beverly Hills Body Cosmetic Plastic And Reconstructive Surgeon Richard Ellenbogen Plastic Surgeon – Babak Dadvand Richard Ellenbogen Beverly Hills Body And Babak Dadvand Richard Ellenbogen – Beverly Hills Body BRIAN WILLIS Brockstar DAN ANTON: BACKLINKSVAULT and BrandlinksRank dan anton Kotton Grammer OMG Machines SCAM Don Tigert granger whitelaw Richard Cosentino John Schmutzer Exotic Images LLC CMC Choppers Jim Haszinger COSENTINO N Ripoff Reports Complaints Reviews Scams Lawsuits and Frauds Reported Jim Haszinger KaonSoftwares Kaon Softwares Emergency Vehicle Lights Light bars Sirens LED Outfitters Lise Winicki LuxSauna Auto Connection Manassas Complaint Review: Poggi Michael Michael Poggi Poggi’s Animal House Complaint Review: Michael Poggi Poggisanimalhouse 9547089441 Complaint Review: Mountain Business Center LLC Rebecca Bextel SwiftUnlocks Elite Client Services Complaint Review: Naushad Noordin Velani Complaint Review: Trey Knight Trey Knight trey night Haskel Grant Knight Haskel G Knight FHTM LIMU Danger Trey Knight Uses fake social security numbers Trey Knight Atlantic Beach, Florida Trey Knight is a Scammer LA Laser Center Gerardo Cornejo Velez 多伦多中医吴冠英 Conslines.com

  4. Executive pleading poverty after $44M judgment Symons and family ordered to pay $34.2 million in fraud case Alan Symons In the United States Court of Appeals Arie Abekasis Diditan Financial ARIE ABEKASIS DIDITAN FINANCIAL DIDITAN GROUP ARIE ABEKASIS OF DIDITAN Richard Ellenbogen – Beverly Hills Body Richard Ellenbogen – Beverly Hills Body – Babak Dadvand Beverly Hills Body Plastic Surgeons – Richard Ellenbogen MD Richard Ellenbogen And Babak Dadvand Plastic Surgeons Of Beverly Hills Richard Ellenbogen Plastic Surgeon And Babak Dadvand Richard Ellenbogen Md Plastic Surgery Rhinoplasty Nose Job Richard Ellenbogen Beverly Hills Body Cosmetic Plastic And Reconstructive Surgeon Richard Ellenbogen Plastic Surgeon – Babak Dadvand Richard Ellenbogen Beverly Hills Body And Babak Dadvand Richard Ellenbogen – Beverly Hills Body BRIAN WILLIS Brockstar DAN ANTON: BACKLINKSVAULT and BrandlinksRank dan anton Kotton Grammer OMG Machines SCAM Don Tigert granger whitelaw Richard Cosentino John Schmutzer Exotic Images LLC CMC Choppers Jim Haszinger COSENTINO N Ripoff Reports Complaints Reviews Scams Lawsuits and Frauds Reported Jim Haszinger KaonSoftwares Kaon Softwares Emergency Vehicle Lights Light bars Sirens LED Outfitters Lise Winicki LuxSauna Auto Connection Manassas Complaint Review: Poggi Michael Michael Poggi Poggi’s Animal House Complaint Review: Michael Poggi Poggisanimalhouse 9547089441 Complaint Review: Mountain Business Center LLC Rebecca Bextel SwiftUnlocks Elite Client Services Complaint Review: Naushad Noordin Velani Complaint Review: Trey Knight Trey Knight trey night Haskel Grant Knight Haskel G Knight FHTM LIMU Danger Trey Knight Uses fake social security numbers Trey Knight Atlantic Beach, Florida Trey Knight is a Scammer LA Laser Center Gerardo Cornejo Velez 多伦多中医吴冠英 Conslines.com

给我留言

留言无头像?


×