1.1.1.4、Fedora

Fedora

Docker 支持Fedora 21和22。 這個頁面將指導你利用Docker發行包託管安裝機構去完成你的安裝。使用這些包確保你可以獲得Docker最新的發行包。如果你希望使用紅帽包管理機構去進行安裝,請查閱 Fedora 發佈文檔去了解如何安裝Docker。

先決條件

Docker 的安裝需要一個64位的Fedora 系統(任何版本)。Docker 要求你的內核必須3.10及以上。

檢查你當前的內核版本,打開一個終端並在上面執行 uname -r 命令去打印你的內核版本信息:

$ uname -r
3.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 Repository
    baseurl=https://yum.dockerproject.org/repo/main/fedora/21
    enabled=1
    gpgcheck=1
    gpgkey=https://yum.dockerproject.org/gpg
    EOF
    

    對於 Fedora 22:

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

    $ sudo yum install docker-engine
  5. 啓動 Docker daemon。

    $ sudo systemctl start docker 
  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/
    

使用腳本安裝

  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 docker
    docker-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. 刪除所有用戶創建的配置文件。

     
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章