CentOS 7 上安装 Docker 详解

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

  1. [root@localhost ~]# yum install docker-io
启动 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 192178b11d362 weeks ago 466.9 MB
  4. centos centos6 70441cac1ed52 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. CentOSLinux release 7.0.1406(Core)
  3. [root@cd05639b3f5c /]#exit
  4. exit
  5. [root@localhost ~]#

转载于:https://my.oschina.net/zhougui/blog/747933

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值