介绍
Docker Image
(镜像)就是一个集装箱,可以看作是封装成了一个小型的操作系统。Docker
就是一个容器,Image
可以在上面运行。- 这样的机制使得,我们只要有
Docker
,就能够在不同系统运行Image
。 Docker
和虚拟机有很大的相似之处,不过Docker
更轻量级,每次不会运行出整个大的操作系统。- 如图所示,
VMware
需要建立多个Guest OS
,而docker
直接利用Host OS
。
Linux
参考官方文档
我这里用的是
Ubuntu
,其余操作系统参考其他文档。
- 移除旧版本
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
- 使用阿里源
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
- 写入软件源
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
- 安装社区版
docker
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
- 测试运行
sudo docker run hello-world
- 有如下显示则安装成功
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/
Windows
我的系统是家庭版(懒),这里还是参考官方文档
-
下载
Docker Desktop
,直接安装。 -
至少选中安装
WSL2
进行,装完后会要求重启。 -
重启后可能报错,点击链接安装更新内核。
-
Restart
之后,我出现了如下情况。 -
按照网上的方法,以管理员身份打开
CMD
,输入命令。
netsh winsock reset
- 重启之后,安装成功。
命令
参考官方文档
- 相关信息
#显示版本
docker version
#显示详细信息
docker info
#显示COMMAND帮助
docker {COMMAND} --help
- 其他命令