- 卸载旧版 Docker(可选):
sudo apt-get remove docker docker-engine docker.io containerd runc
- 更新 apt 包索引并安装依赖:
sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release
- 添加 Docker 的官方 GPG 密钥:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
- 添加 Docker 包存储库:
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
- 更新 apt 包索引再次进行安装:
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
- (可选)添加当前用户到
docker
用户组:
sudo usermod -aG docker $USER
- (可选)启动 Docker 服务:
sudo systemctl start docker
现在,Docker 已安装并准备好在 Ubuntu 上运行容器。您可以通过使用 docker
命令在终端中管理容器和镜像。
- 测试
echohye@echohye-virtual-machine:~/桌面$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:4e83453afed1b4fa1a3500525091dbfca6ce1e66903fd4c01ff015dbcb1ba33e
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/
箴言:因为这些东西是非常简单的。不要抱怨自己学不会,那是因为你没有足够用心。