1.1.1.2、Red Hat Enterprise Linux

红帽企业版

Docker 支持红帽企业版 7。 这个页面将指导你利用Docker发行包托管安装机构去完成你的安装。使用这些包确保你可以获得Docker最新的发行包。如果你希望使用红帽包管理机构去进行安装,请查阅红帽发布文档去了解如何安装Docker。

先决条件

Docker 的安装需要一个64位的红帽系统(任何版本)。Docker 要求你的内核必须3.10及以上。

检查你当前的内核版本,打开一个终端并在上面执行 uname -r 命令去打印你的内核版本信息:

$ uname -r
3.10.0-229.el7.x86_64

最后,建议你完全升级你的系统。请牢记,及时修复你系统上的所有补丁去规避一些潜在的bug。任何已经报告的bug都有可能在新的内核包中已经被修复。

安装Docker 引擎

这里有两种方法去安装Docker引擎。你可以使用 yum 包管理器直接自己安装。或者,你可以使用 curl 连接到 get.docker.com 站点进行安装。第二种方法通过执行一个安装脚本,其底层也是通过 yum 包管理器去完成安装。

使用 yum 安装

  1. 使用用户 sudo 或root 权限登陆到你的系统。

  2. 确认你的当前的 yum 包都已经是最新的。

    $ sudo yum update
  3. 添加 yum repo。

    $ cat >/etc/yum.repos.d/docker.repo <<-EOF
    [dockerrepo]
    name=Docker Repository
    baseurl=https://yum.dockerproject.org/repo/main/centos/7
    enabled=1
    gpgcheck=1
    gpgkey=https://yum.dockerproject.org/gpg
    EOF
    
  4. 安装Docker包。

    $ sudo yum install docker-engine
  5. 启动 Docker daemon。

    $ sudo service docker start
    
  6. 通过在一个容器运行一个测试镜像来核实 docker 是否被正确的安装。

    $ sudo docker run hello-world
    Unable to find image 'hello-world:latest' locally
        latest: Pulling from hello-world
        a8219747be10: Pull complete
        91c95931e552: Already exists
        hello-world:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security.
        Digest: sha256:aa03e5d0d5553b4c3473e89c8619cf79df368babd1.7.1cf5daeb82aab55838d
        Status: Downloaded newer image for hello-world:latest
        Hello from Docker.
        This message shows that your installation appears to be working correctly.
    
    
        To generate this message, Docker took the following steps:
         1. The Docker client contacted the Docker daemon.
         2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
                (Assuming it was not already locally available.)
         3. The Docker daemon created a new container from that image which runs the
                executable that produces the output you are currently reading.
         4. The Docker daemon streamed that output to the Docker client, which sent itto your terminal.
    
    
        To try something more ambitious, you can run an Ubuntu container with:
         $ docker run -it ubuntu bash
    
    
        For more examples and ideas, visit:
         http://docs.docker.com/userguide/
    

使用脚本安装

所有CentOS的版本的安装过程都是一样的。

  1. 使用用户的 sudo 或 root 权限登陆到系统。.

  2. 确保你当前的 yum 包都已经是最新的。

    $ sudo yum update
  3. 执行 Docker 安装脚本。

    $ curl -sSL https://get.docker.com/ | sh
  4. 启动 Docker daemon。

    $ sudo service docker start
    
  5. 通过在一个容器运行一个测试镜像来核实 docker 是否被正确的安装。

    $ sudo docker run hello-world
    

创建一个docker组

docker daemon 绑定一个 Unix socket 替代你一个 TCP端口。默认情况下,Unix socket 属于 root 用户,其他用户只能使用 sudo 才能访问。正是因为这个原因, docker daemon 总是需要 root 用户启动。

为了避免每次使用 docker 命令时,需要频繁追加 sudo ,可以创建一个名为 docker 组并把有需要的用户添加进去。当 docker daemon 启动时,通过 docker 组可以共享Unix Socket的读写权限。

警告 docker  组是和  root  用户等价的。关于这个设置对系统安全影响,请移步  Docker Daemon 的攻击面 去了解更多。

创建一个 docker 组并添加你的用户:

  1. 使用 sudo 特权登陆到你的系统。

    这个过程里,假定你使用 ubuntu 用户登录。

  2. 创建 docker 组并添加你的用户。

    $ sudo usermod -aG docker ubuntu
    
  3. 先登出,然后再登陆。

    这样确保你的用户权限的正确性。

  4. 通过执行不带 sudo 的 docker 命令来核实设置是否成功。

    $ docker run hello-world

设置 Docker daemon 开机启动

设置 Docker 跟随你的系统启动,可以如下设置:

$ sudo chkconfig docker on

如果你需要添加一个 HTTP 代理,为 Docker 运行时文件设置一个不同的目录或一个分区,或者其他定制化的设置,请参考Systemd文章去了解更多如何去使用你的 Systemd 定制化Docker daemon 选项

卸载

你可以使用 yum 卸载Docker。

  1. 列出你已经安装的包。

    $ yum list installed | grep docker
    yum list installed | grep docker
    docker-engine.x86_64                1.7.1-0.1.el7@/docker-engine-1.7.1-0.1.el7.x86_64
    
  2. 移除包。

    $ sudo yum -y remove docker-engine.x86_64

    这条命令不会删除在你的主机上的镜像、容器、数据卷或用户创建的配置文件。

  3. 使用如下命令删除镜像、容器、数据卷:

    $ rm -rf /var/lib/docker
    
  4. 删除所有用户创建的配置文件。

     
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值