官方文檔連接地址:https://docs.docker.com/install/linux/docker-ce/ubuntu/#set-up-the-repositorylinux
一 卸載安裝docker
1 卸載舊版本shell
sudo apt-get remove docker docker-engine docker.io
2 安裝ubuntu
方式一 腳本安裝curl
curl -fsSL get.docker.com -o get-docker.sh * curl -f 鏈接失敗時不顯示HTTP錯誤信息 * curl -s Silent模式。不輸出任務內容 * curl -S 顯示錯誤. 在選項 -s 中,當 curl 出現錯誤時將顯示 * curl -L 跟蹤重定向 * curl -o 將輸出寫入文件,而非 stdout sudo sh get-docker.sh --mirror Aliyun
方式二this
(應該能夠跳過)因爲apt源使用HTTPS以確保軟件下載過程當中不被篡改。所以,咱們首先須要添加使用HTTPS傳輸的軟件包以及CA證書。url
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
(應該能夠跳過)爲了確認所下載軟件包的合法性,須要添加軟件源的GPG密鑰。spa
國內源: curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add - 官方源: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
而後,咱們須要向 source.list 中添加Docker軟件源code
國內源: sudo add-apt-repository "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable" 官方源: sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
安裝docker ce (ce 社區版本)rem
sudo apt-get update sudo apt-get install docker-ce
*********************************************************************************************************
*** 安裝完成以後,會多一個docker用戶組。默認只有docker組和root用戶能夠使用。
執行 sudo usermod -aG docker your-user 用戶添加到docker組裏,
Run this command in your favourite shell and then completely log out of your account and log back in (if in doubt, reboot!):
重啓系統以後,就能夠使用設置用戶使用docker了。
*********************************************************************************************************
*** 進入/etc/下
user@user: ll |grep docker drwx------ 2 root root 4096 4月 4 10:41 docker/
更改docker文件夾組屬性(非必須)
user@user:/etc$ sudo chgrp -R docker docker/ user@user:/etc$ ll | grep docker drwx------ 2 root docker 4096 4月 4 10:41 docker/ user@user:/etc$ sudo chmod -R 770 docker/ user@user:/etc$ ll | grep docker drwxrwx--- 2 root docker 4096 4月 4 10:41 docker/
*********************************************************************************************************
3 徹底卸載
sudo apt-get purge docker-ce sudo rm -rf /var/lib/docker
二 設置鏡像加速器
使用阿里的docker鏡像服務 訪問:https://cr.console.aliyun.com/ 註冊以後,在鏡像加速器就能夠看到設置方法。
三 hello world
執行該命令:會下載hello-world鏡像,而後執行。
docker run hello-world
查看下載鏡像
docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest f2a91732366c 4 months ago 1.85kB
刪除鏡像
docker image rm -f hello-world:latest Untagged: hello-world:latest Untagged: hello-world@sha256:97ce6fa4b6cdc0790cda65fe7290b74cfebd9fa0c9b8c38e979330d547d22ce1 Deleted: sha256:f2a91732366c0332ccd7afd2a5c4ff2b9af81f549370f7a19acd460f87686bc7 user@user:/etc/docker$ docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE 說明 docker image rm --help Usage: docker image rm [OPTIONS] IMAGE [IMAGE...] Remove one or more images Aliases: rm, rmi, remove Options: -f, --force Force removal of the image --no-prune Do not delete untagged parents