1.1.1.3、CentOS

CentOS

Docker 运行在CentOS 7.X上。 Docker可以在一个兼容EL7系统(如:Scientific Linux)上安装成功,但是,Docker 对这些发行版不提供任何的测试和支持。

这个章节会指导你使用Docker-managed发布包和安装机制去安装。使用这个包确保你获得Docker的最新发行版。如果你希望使用CentOS-managed 包,请查阅Centos的相关文档。

先决条件

Docker 的安装,需要一个不管任何版本的64位CentOS系统。并且,你的内核必须要3.10以上,例如,CentOS 7。

检查你当前系统的内核版本,打开一个终端并执行 uname -r 命令去显示你的内核版本:

$ uname -r
3.10.0-229.el7.x86_64

最后,建议你全面升级你的系统。务必牢记,给你的系统打补丁以修复内核任何潜在的bug。任何已经报告的内核bug,可能在最新的内核包中已经修复了。

安装

这里提供两种方法去安装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. 通过运行一个测试镜像到一个容器里,核实安装是否成功。

    $ 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/
    

使用脚本安装

  1. 携带着 sudo 或root 的权限登陆到你的机器。
  2. $ sudo yum update
  3. 执行 Docker 安装脚本。

    $ curl -sSL https://get.docker.com/ | sh

    这个脚本添加了 docker.repo 仓库并安装Docker。

  4. 启动 Docker daemon。

    $ sudo service docker start
    
  5. 通过运行一个测试镜像到一个容器里,核实安装是否成功。

    $ sudo docker run hello-world
    

创建一个 docker 组

docker daemon 绑定到一个 Unix socket 替代一个 TCP 端口。默认情况下,Unix socket 是归 root 用户所有,其他用户要在命令前面追加 sudo 才能访问。由此, docker daemon 总是作为 root 用户的专属。

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

警告:docker 组等同 root 用户;势必会对你的系统注入安全隐患,可以移步到 Docker Daemon 攻击面 获取更多的相关信息。

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

  1. 使用 sudo 权限登陆到你的CentOS中。

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

    sudo usermod -aG docker your_username

  3. 登出并重新登陆。

    这样保证你的用户使用正确的权限运行。

  4. 通过执行不带 sudo 的 docker 命令来核实上述配置是否生效。

    $ docker run hello-world
    

设置 docker daemon 自动启动

确保 Docker 在你的系统启动时跟随西东,可以执行如下指令:

  $ sudo chkconfig docker on

如果你需要一个HTTP代理,为Docker运行时文件设置一个不同的目录或分区,或者其他的自定义需求,请参考customize your Systemd Docker daemon options

卸载

你可以使用 yum 删除Docker。 

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

    $ yum list installed | grep docker
    yum list installed | grep docker
    docker-engine.x86_64   1.7.1-1.el7 @/docker-engine-1.7.1-1.el7.x86_64.rpm
    
  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、付费专栏及课程。

余额充值