Ubuntu 20.0.4 安裝 Docker
- 卸載舊版本 Docker
- 配置軟體源
- 更新軟體源并安裝依賴包
- 添加 Docker 官方軟體包密鑰
- 添加軟體源
- 安裝 Docker
- 卸載 Docker
- 卸載軟體
- 洗掉鏡像、容器、自定義配置等檔案
- 安裝 Docker-Compose
- 卸載 Docker-Compose
卸載舊版本 Docker
sudo apt-get remove docker docker-engine docker.io containerd runc
配置軟體源
更新軟體源并安裝依賴包
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
添加 Docker 官方軟體包密鑰
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
驗證密鑰是否安裝成功
toor@toor:~/Desktop$ sudo apt-key fingerprint 0EBFCD88
pub rsa4096 2017-02-22 [SCEA]
9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid [ unknown] Docker Release (CE deb) <docker@docker.com>
sub rsa4096 2017-02-22 [S]
添加軟體源
查詢當前系統所基于的 Debian 版本,得到以下回顯
toor@toor:~/Desktop$ cat /proc/version
Linux version 5.8.0-63-generic (buildd@lgw01-amd64-035) (gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #71~20.04.1-Ubuntu SMP Thu Jul 15 17:46:08 UTC 2021
通過查詢得知 Debian 9 對應的代號為 stretch ,之后執行以下命令寫入 docker 軟體源
echo 'deb https://download.docker.com/linux/debian stretch stable' | sudo tee -a /etc/apt/sources.list.d/docker.list
正常寫入回顯
toor@toor:~/Desktop$ echo 'deb https://download.docker.com/linux/debian stretch stable' | sudo tee -a /etc/apt/sources.list.d/docker.list
[sudo] password for toor:
deb https://download.docker.com/linux/debian stretch stable

安裝 Docker
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io -y
安裝之后可以配置一下 Docker 鏡像加速
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["http://hub-mirror.c.163.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
配置好后執行以下命令進行測驗
sudo docker run hello-world
得到以下回顯顯示為正常
toor@toor:~/Desktop$ sudo docker run hello-world
[sudo] password for toor:
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:df5f5184104426b65967e016ff2ac0bfcd44ad7899ca3bbcf8e44e4461491a9e
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://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
卸載 Docker
卸載軟體
sudo apt-get purge docker-ce docker-ce-cli containerd.io
洗掉鏡像、容器、自定義配置等檔案
sudo rm -rf /var/lib/docker
安裝 Docker-Compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose -v
回顯版本號則安裝成功
卸載 Docker-Compose
sudo rm /usr/local/bin/docker-compose
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/289958.html
標籤:其他
