近日在研究容器相關(guān)的技術(shù),看了vagrant和Docker,最終我選擇兩個都研究下,現(xiàn)在我們來看看Docker的環(huán)境搭建。
零. 前期說明
筆者所有的操作系統(tǒng)是DeepIn 15.5,這個由深度科技基于Debian開發(fā)的操作系統(tǒng)。
基于以上的條件,我們安裝Docker也會參考Docker官網(wǎng)上關(guān)于Debian的安裝手冊。
傳送門:Get Docker CE for Debian官方手冊
一、準(zhǔn)備工作
掃盲
| English | 中文 |
|---|---|
| host | 本地主機 |
| image | 鏡像 |
| contianer | 容器 |
| registry | 倉庫 |
| daemon | 守護進程 |
| client | 客戶端 |
卸載之前的Docker
sudo apt-get remove docker docker-engine docker.io
更新apt軟件索引
sudo apt-get update
二、開始安裝Docker
安裝所依賴的庫文件
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg2 \
software-properties-common \
python-software-properties
添加Docker的官方GPG
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
添加source.list添加Docker源
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian wheezy stable“
最后更新源
sudo apt-get update
三、安裝Docker-ce
sudo apt-get -y install docker-ce
非root用戶身份管理Docker
創(chuàng)建docker用戶組
sudo groupadd docker
將當(dāng)前用戶添加到docker用戶組
sudo gpasswd -a ${USER} docker
修改docker.sock的權(quán)限
sudo chmod a+rw /var/run/docker.sock
四、注銷并重新登
到目前為止,docker在Deepin中已經(jīng)安裝完成,現(xiàn)在可以注銷并重新登錄你的組成員權(quán)限。
五、檢測權(quán)限
docker run hello-world
驗證您可以運行
docker命令時不需要添加sudo。
該命令會下載一個測試Image并在容器中運行。
如果成功了,可以看到一下信息:
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest: sha256:66ef312bbac49c39a89aa9bcc3cb4f3c9e7de3788c944158df3ee0176d32b751
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.
(amd64)
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 it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://cloud.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/
六、禁止Docker開機自動啟動
安裝chkconfig
sudo apt-get install chkconfig
禁止開機自動啟動
sudo chkconfig --del docker