1. 安装Docker
1.1 安装KVM
参考: https://ubuntu.com/blog/kvm-hyphervisor
1
| sudo apt -y install bridge-utils cpu-checker libvirt-clients libvirt-daemon qemu qemu-kvm
|
检查虚拟化功能
1.2 安装Docker
参考资料: https://docs.docker.com/engine/install/ubuntu/
我对Docker Desktop并不感兴趣, 因此选择安装无图形界面的Docker Engine
- 卸载旧版本
1
| sudo apt-get remove docker docker-engine docker.io containerd runc
|
- 设置软件源
1 2 3 4 5 6 7 8
| sudo apt update sudo apt install ca-certificates curl gnupg lsb-release sudo mkdir -p /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null sudo apt-get update
|
- 安装Docker Engine
1
| sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
|
- 配置权限
1 2 3 4 5 6 7 8 9
| sudo groupadd docker sudo groupadd libvirt sudo groupadd kvm sudo adduser $USER docker sudo adduser $USER libvirt sudo adduser $USER kvm newgrp kvm newgrp docker newgrp libvirt
|
newgrp
用于重新以对应群组身份登陆
2. Docker 的常用命令
构建镜像
1
| docker build -f <dockerfile> -t <image_name:tag> .
|