紅帽企業版
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 安裝
-
使用用戶
sudo
或root
權限登陸到你的系統。 -
確認你的當前的 yum 包都已經是最新的。
$ sudo yum update
-
添加 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
-
安裝Docker包。
$ sudo yum install docker-engine
-
啓動 Docker daemon。
$ sudo service docker start
-
通過在一個容器運行一個測試鏡像來覈實
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的版本的安裝過程都是一樣的。
-
使用用戶的
sudo
或root
權限登陸到系統。. -
確保你當前的 yum 包都已經是最新的。
$ sudo yum update
-
執行 Docker 安裝腳本。
$ curl -sSL https://get.docker.com/ | sh
-
啓動 Docker daemon。
$ sudo service docker start
-
通過在一個容器運行一個測試鏡像來覈實
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
組並添加你的用戶:
-
使用
sudo
特權登陸到你的系統。這個過程裏,假定你使用
ubuntu
用戶登錄。 -
創建
docker
組並添加你的用戶。$ sudo usermod -aG docker ubuntu
-
先登出,然後再登陸。
這樣確保你的用戶權限的正確性。
-
通過執行不帶
sudo
的docker
命令來覈實設置是否成功。$ docker run hello-world
設置 Docker daemon 開機啓動
設置 Docker 跟隨你的系統啓動,可以如下設置:
$ sudo chkconfig docker on
如果你需要添加一個 HTTP 代理,爲 Docker 運行時文件設置一個不同的目錄或一個分區,或者其他定製化的設置,請參考Systemd文章去了解更多如何去使用你的 Systemd 定製化Docker daemon 選項。
卸載
你可以使用 yum
卸載Docker。
-
列出你已經安裝的包。
$ 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
-
移除包。
$ sudo yum -y remove docker-engine.x86_64
這條命令不會刪除在你的主機上的鏡像、容器、數據卷或用戶創建的配置文件。
-
使用如下命令刪除鏡像、容器、數據卷:
$ rm -rf /var/lib/docker
-
刪除所有用戶創建的配置文件。