1.1.1.4、Fedora

来源:互联网 发布:mac热血无赖存档 编辑:程序博客网 时间:2024/05/19 11:37

Fedora

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

先决条件

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

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

$ uname -r3.19.5-100.fc21.x86_64

如果你的内核还很久,你必须先升级它。

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

安装

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

使用 yum 安装

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

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

    $ sudo yum update
  3. 添加 yum repo。

    对于 Fedora 21:

    $ cat >/etc/yum.repos.d/docker.repo <<-EOF[dockerrepo]name=Docker Repositorybaseurl=https://yum.dockerproject.org/repo/main/fedora/21enabled=1gpgcheck=1gpgkey=https://yum.dockerproject.org/gpgEOF

    对于 Fedora 22:

    $ cat >/etc/yum.repos.d/docker.repo <<-EOF[dockerrepo]name=Docker Repositorybaseurl=https://yum.dockerproject.org/repo/main/fedora/22enabled=1gpgcheck=1gpgkey=https://yum.dockerproject.org/gpgEOF
  4. 安装 Docker 包。

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

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

    $ sudo docker run hello-worldUnable to find image 'hello-world:latest' locallylatest: Pulling from hello-worlda8219747be10: Pull complete91c95931e552: Already existshello-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.1cf5daeb82aab55838dStatus: Downloaded newer image for hello-world:latestHello 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 bashFor more examples and ideas, visit: http://docs.docker.com/userguide/

使用脚本安装

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

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

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

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

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

  4. 启动 Docker daemon。

    $ sudo systemctl start docker 
  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 的攻击面去了解更多。

  1. 创建一个 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 选项

在一个手动创建的网络里运行 Docker

如果你使用219及更高版本的 systemd 子命令 systemd-network 手动配置你的网络,Docker 启动的容器可能无法访问你的网络。从220版本开始,对于一个给定网络 (net.ipv4.conf.<interface>.forwarding的转发设置默认是关闭的。这样的设置阻止IP的转发。这个设置跟 Docker 设置在容器内的net.ipv4.conf.all.forwarding 相冲突。

为了解决这个问题,可以编辑在你Docker宿主机 /usr/lib/systemd/network/ 目录下的 <interface>.network 文件 (如:/usr/lib/systemd/network/80-container-host0.network) 添加以下内容块:

[Network]...IPForward=kernel# ORIPForward=true...

这样配置允许IP转发来自容器所期望的请求。

卸载

  1. 你可以使用 yum 卸载Docker。

    列出你已经安装的包。

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

    $ sudo yum -y remove docker-engine.x86_64

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

  3. 执行如下命令,删除所有的镜像、容器和数据卷:

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

    来源: <https://docs.docker.com/engine/installation/fedora/>
     
0 0
原创粉丝点击