Basic configuration of Docker

介绍

  • Docker Image(镜像)就是一个集装箱,可以看作是封装成了一个小型的操作系统。
  • Docker就是一个容器,Image可以在上面运行。
  • 这样的机制使得,我们只要有Docker,就能够在不同系统运行Image
  • Docker和虚拟机有很大的相似之处,不过Docker更轻量级,每次不会运行出整个大的操作系统。
  • 如图所示,VMware需要建立多个Guest OS,而docker直接利用Host OS

Linux

参考官方文档

我这里用的是Ubuntu,其余操作系统参考其他文档。

  • 移除旧版本
1
sudo apt-get remove docker docker-engine docker.io containerd runc
  • 准备相关依赖
1
2
3
4
5
6
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg
  • 使用阿里源
1
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
  • 写入软件源
1
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
  • 安装社区版docker
1
2
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
  • 测试运行
1
sudo docker run hello-world
  • 有如下显示则安装成功
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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,输入命令。

1
netsh winsock reset
  • 重启之后,安装成功。

命令

参考官方文档

  • 相关信息
1
2
3
4
5
6
#显示版本
docker version
#显示详细信息
docker info
#显示COMMAND帮助
docker {COMMAND} --help
  • 其他命令