安裝Docker
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# 添加軟件源
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sudo yum makecache fast
sudo yum -y install docker-ce
配置文件
默認沒有這些配置文件,手動創建即可
- /etc/default/docker ==> service啓動配置文件
- /etc/docker/daemon.json ==> 1.12版本後萬能配置文件
編輯/etc/docker/daemon.json
,如果沒有就創建一個:
sudo mkdir /etc/docker
vim /etc/docker/daemon.json
寫入如下內容:
{
"storage-driver": "devicemapper"
}
啓動三連
sudo systemctl start docker
sudo systemctl status docker
# 設置開機啓動
sudo systemctl enable docker
鏡像下載加速
由於 Docker Hub 的服務器在國外,下載鏡像會比較慢。
可以在 daocloud.io 免費註冊一個用戶,可直接用GitHub用戶註冊。進入加速器頁面: https://www.daocloud.io/mirror
對於linux平臺,下面有一行腳本,執行並重啓docker
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io
sudo systemctl restart docker.service
該腳本可以將 --registry-mirror 加入到你的 Docker 配置文件 /etc/docker/daemon.json 中。適用於 Ubuntu14.04、Debian、CentOS6 、CentOS7、Fedora、Arch Linux、openSUSE Leap 42.1,其他版本可能有細微不同。更多詳情請訪問文檔。
測試docker
運行hello world
鏡像以測試容器是否正確安裝:
sudo docker run hello-world
或者運行一個httpd鏡像:
docker run -d -p 9898:80 httpd
從 Docker Hub 下載 httpd 鏡像。鏡像中已經安裝好了 Apache HTTP Server,並將容器的 80 端口映射到 host 的 9898 端口