參考文檔:https://docs.docker.com/install/linux/docker-ce/centos/#install-using-the-repositorylinux
Docker 要求 CentOS 系統的內核版本高於 3.10,在終端輸入如下命令:docker
uname -r
若是安裝舊版本,輸入如下命令刪除及相關的依賴項,若是沒有安裝過,跳過。json
yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine
手動刪除鏡像/容器等centos
rm -rf /var/lib/docker
若是提示未安裝這些軟件包,則能夠。app
yum install -y yum-utils \ device-mapper-persistent-data \ lvm2
yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo
yum install -y docker-ce
systemctl start docker
systemctl status docker
hello-world
映像來驗證是否正確安裝docker run hello-world
出現 Hello from Docker!即安裝成功。阿里雲
設置開機啓動spa
systemctl enable docker
有時間拉取鏡像的時候,速度可慢,還有可能傳輸異常。rest
在/etc/docker目錄下找到在daemon.json文件(沒有就新建),將下面內容寫入日誌
{ "registry-mirrors": ["https://xxxxxxxxmirror.aliyuncs.com"] }
registry-mirrors 就是上面加速器地址code
systemctl daemon-reload
systemctl restart docker
能夠直接在終端輸入 docker --help 列出全部docker的用法以及全部命令
docker images #查看本地鏡像
docker rmi 鏡像ID
docker rmi -f 鏡像ID
#強制刪除 若是鏡像有容器在運行 那麼就須要強制刪除 增長 -f 參數
docker run --name demo -d -p 8080:8080 aspnetcore #-d 後臺運行 #-p 端口映射 格式爲:主機(宿主)端口:容器端口 #--name 容器名稱 #最有一個爲鏡像名稱docker ps #查看當前正在運行的容器 docker ps -a #查看全部容器的狀態 docker start/stop/restart 容器id #啓動/中止/重啓某個容器 docker rm 容器id #刪除某個容器docker logs 容器id #容器日誌