參考博客:Ubuntu 20.04 安裝 docker 詳解
參考博客:Ubuntu Docker 安裝
刪除現(xiàn)有的docker
干凈的卸載掉你系統(tǒng)中的 docker,參考官網(wǎng)操作
jun@jun-VirtualBox:/var/lib$ sudo apt-get purge docker-ce docker-ce-cli containerd.io
jun@jun-VirtualBox:/var/lib$ rm -rf /var/lib/docker
jun@jun-VirtualBox:/var/lib$ sudo apt-get remove docker docker-engine docker.io containerd runc
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package docker-engine
jun@jun-VirtualBox:/var/lib$
更新軟件源
jun@jun-VirtualBox:/var/lib$ sudo apt-get update
安裝依賴
jun@jun-VirtualBox:/var/lib$ sudo apt install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
添加docker官方GPG密鑰
jun@jun-VirtualBox:/var/lib$ curl -fgSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 3817 100 3817 0 0 6889 0 --:--:-- --:--:-- --:--:-- 6889
OK
驗證密鑰
jun@jun-VirtualBox:/var/lib$ 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]
jun@jun-VirtualBox:/var/lib$
使用以下指令設(shè)置穩(wěn)定版?zhèn)}庫
sudo add-apt-repository \
"deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/ \
$(lsb_release -cs) \
stable"
安裝docker
- 安裝最新版本的docker engine-community 和 containerd
jun@jun-VirtualBox:/var/lib$ sudo apt-get install docker-ce docker-ce-cli containerd.io
- 要安裝特定版本的 Docker Engine-Community,請在倉庫中列出可用版本,然后選擇一種安裝。列出您的倉庫中可用的版本
jun@jun-VirtualBox:/var/lib$ apt-cache madison docker-ce
docker-ce | 5:20.10.12~3-0~ubuntu-focal | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.11~3-0~ubuntu-focal | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.10~3-0~ubuntu-focal | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.9~3-0~ubuntu-focal | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.8~3-0~ubuntu-focal | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.7~3-0~ubuntu-focal | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.6~3-0~ubuntu-focal | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.5~3-0~ubuntu-focal | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.4~3-0~ubuntu-focal | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.3~3-0~ubuntu-focal | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.2~3-0~ubuntu-focal | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.1~3-0~ubuntu-focal | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:20.10.0~3-0~ubuntu-focal | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:19.03.15~3-0~ubuntu-focal | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:19.03.14~3-0~ubuntu-focal | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:19.03.13~3-0~ubuntu-focal | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:19.03.12~3-0~ubuntu-focal | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:19.03.11~3-0~ubuntu-focal | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:19.03.10~3-0~ubuntu-focal | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages
docker-ce | 5:19.03.9~3-0~ubuntu-focal | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu focal/stable amd64 Packages
jun@jun-VirtualBox:/var/lib$
使用第二列中的版本字符串安裝特定版本,例如 5:19.03.93-0ubuntu-focal,
sudo apt-get install docker-ce=<5:19.03.9~3-0~ubuntu-focal > docker-ce-cli=<5:19.03.9~3-0~ubuntu-focal > containerd.io
或者安裝最新版本
sudo apt-get install docker-ce docker-ce-cli containerd.io
測試docker運行
jun@jun-VirtualBox:/var/lib$ sudo docker run hello-world
jun@jun-VirtualBox:/var/lib$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:975f4b14f326b05db86e16de00144f9c12257553bba9484fed41f9b6f2257800
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/
查看當(dāng)前運行的docker容器
jun@jun-VirtualBox:/var/lib$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9fcff7d0b92c hello-world "/hello" About a minute ago Exited (0) About a minute ago epic_tesla
a82814aee7a7 hello-world "/hello" 8 minutes ago Exited (0) 8 minutes ago exciting_chaum
jun@jun-VirtualBox:/var/lib$
查看docker服務(wù)運行狀態(tài)
jun@jun-VirtualBox:/var/lib$ sudo systemctl status docker
jun@jun-VirtualBox:/var/lib$ sudo systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2022-01-16 15:42:42 CST; 5s ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 23397 (dockerd)
Tasks: 8
Memory: 29.0M
CGroup: /system.slice/docker.service
└─23397 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
1月 16 15:42:42 jun-VirtualBox dockerd[23397]: time="2022-01-16T15:42:42.434888523+08:00" level=warning msg="Your kernel does not supp>
1月 16 15:42:42 jun-VirtualBox dockerd[23397]: time="2022-01-16T15:42:42.435071473+08:00" level=warning msg="Your kernel does not supp>
1月 16 15:42:42 jun-VirtualBox dockerd[23397]: time="2022-01-16T15:42:42.435155074+08:00" level=warning msg="Your kernel does not supp>
1月 16 15:42:42 jun-VirtualBox dockerd[23397]: time="2022-01-16T15:42:42.435349663+08:00" level=info msg="Loading containers: start."
1月 16 15:42:42 jun-VirtualBox dockerd[23397]: time="2022-01-16T15:42:42.508460852+08:00" level=info msg="Default bridge (docker0) is >
1月 16 15:42:42 jun-VirtualBox dockerd[23397]: time="2022-01-16T15:42:42.536441028+08:00" level=info msg="Loading containers: done."
1月 16 15:42:42 jun-VirtualBox dockerd[23397]: time="2022-01-16T15:42:42.581529559+08:00" level=info msg="Docker daemon" commit=459d0d>
1月 16 15:42:42 jun-VirtualBox dockerd[23397]: time="2022-01-16T15:42:42.581581379+08:00" level=info msg="Daemon has completed initial>
1月 16 15:42:42 jun-VirtualBox systemd[1]: Started Docker Application Container Engine.
1月 16 15:42:42 jun-VirtualBox dockerd[23397]: time="2022-01-16T15:42:42.614719728+08:00" level=info msg="API listen on /run/docker.so>
jun@jun-VirtualBox:/var/lib$
重啟docker服務(wù)
jun@jun-VirtualBox:/var/lib$ sudo systemctl restart docker
jun@jun-VirtualBox:/var/lib$ sudo systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2022-01-16 15:44:02 CST; 1s ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 23527 (dockerd)
Tasks: 8
Memory: 27.1M
CGroup: /system.slice/docker.service
└─23527 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
服務(wù)相關(guān)命令
$ sudo systemctl enable docker #開機自啟動docker服務(wù)
$ sudo systemctl status docker #查看服務(wù)docker運行狀態(tài)
$ sudo systemctl start docker #啟動docker服務(wù)
$ sudo systemctl stop docker #停止docker服務(wù)
$ sudo systemctl restart docker #重啟docker服務(wù)
docker使用參考docker 使用隨記