使用存儲庫安裝
1.安裝所需的軟件包
sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
2.使用如下命令設置穩定的存儲庫
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
3.安裝最新版本的docker社區版
sudo yum install docker-ce docker-ce-cli containerd.io
4.啓動docker
systemctl start docker
提示Failed to start docker.service: Unit not found.
docker鏡像下載失敗
http://ftp.sjtu.edu.cn/centos/7.6.1810/extras/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
解決方法:
1.修改yum源
cd /etc/yum.repos.d/
ll
刪除docker-ce.repo
rm -rf docker-ce.repo
添加國內的yum源
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
再次執行安裝命令
yum install docker-ce docker-ce-cli containerd.io
還是提示 404
http://ftp.sjtu.edu.cn/centos/7.6.1810/extras/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
2.清除yum緩存
yum clean all
rm -rf /var/cache/yum/*
再安裝docker
yum install docker-ce docker-ce-cli containerd.io
啓動docker
systemctl start docker
運行hello-world
docker run hello-world
Unable to find image ‘hello-world:latest’ locally
docker: Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).
登錄docker
docker login
配置國內鏡像站
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io
重啓docker服務
service docker restart
運行hello-world容器
docker run hello-world
查看容器
docker ps -a
參考
https://docs.docker.com/install/linux/docker-ce/centos/#install-using-the-convenience-script
https://wiki.centos.org/yum-errors
https://www.daocloud.io/mirror#accelerator-doc