Windows Docker 安装

Docker 主要利用 Linux 内核的 namespace、cgroup 和 unionFS 三种技术,实现了容器的环境隔离、资源控制和镜像打包等功能。

Docker 容器的运行必须依赖于 Linux 内核环境,所以 Docker 必须部署在 Linux 内核的系统上。

如果要在非 Linux 内核的系统上部署 Docker,就必须安装一个虚拟的 Linux 环境。

 

1. Windows 系统的 Docker 组件

在 Windows 系统上部署 Docker 的方法都是先安装一个虚拟机,并在安装 Linux 系统的的虚拟机中运行 Docker。

在 Windows 系统上部署 Docker 各组件关系:


 

2. Win10 系统部署 Docker

Docker Desktop 是 Docker 在 Win10 上的官方安装方式。

Docker Desktop 先在虚拟机中安装 Linux,然后再安装 Docker。

Docker Desktop 官方下载地址: https://hub.docker.com/editions/community/docker-ce-desktop-windows


1)安装 Hyper-V

Hyper-V 是微软开发的虚拟机,类似于 VMWare 或 VirtualBox,仅适用于 Windows 10。

它是 Docker Desktop 使用的虚拟机。

如果 Hyper-V 虚拟机一旦启用,QEMU、VirtualBox 或 VMWare Workstation 15 及以下版本将无法使用!如果你必须在电脑上使用其他虚拟机,请不要使用 Hyper-V!


2)开启 Hyper-V

 

在 "启用或关闭Windows" 功能中:选中Hyper-V。

 

启用 Hyper-V 还可以通过命令行的方式,请右键开始菜单并以管理员身份运行 PowerShell,执行以下命令:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All

3)安装 Docker Desktop for Windows

点击 Get started with Docker Desktop,并下载 Windows 的版本,如果你还没有登录,会要求注册登录:

4)运行安装文件

双击下载的 Docker for Windows Installer 安装文件,一路 Next,点击 Finish 完成安装。

安装完成后,Docker 会自动启动。通知栏上会出现个小鲸鱼的图标,这表示 Docker 正在运行。

如果没启动,你可以在 Windows 搜索 Docker 来启动:

启动后,也可以在通知栏上看到小鲸鱼图标:

如果启动中遇到因 WSL 2 导致地错误,请安装 WSL 2。

4)验证 Docker Desktop 是否安装成功

打开 PowerShell 输入指令后,打印以下信息则安装成功:

$ docker run hello-world

执行结果为:
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete 
Digest: sha256:f2266cbfc127c960fd30e76b7c792dc23b588c0db76233517e1891a4e357d519
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/

 

3. Win7/Win8/XP/Vista 系统部署 Docker

Win7/Win8/XP/Vista 等需要利用 Docker Toolbox 来安装,国内可以使用阿里云的镜像来下载,下载地址:http://mirrors.aliyun.com/docker-toolbox/windows/docker-toolbox/

1)安装 Docker Toolbox

双击运行安装包,点下一步即可,可以勾选自己需要的组件:

docker toolbox 是一个工具集,它主要包含以下一些内容:

  • Docker CLI - 客户端,用来运行 docker 引擎创建镜像和容器。
  • Docker Machine - 可以让你在 Windows 的命令行中运行 docker 引擎命令。
  • Docker Compose - 用来运行 docker-compose 命令。
  • Kitematic - 这是 Docker 的 GUI 版本。
  • Docker QuickStart shell - 这是一个已经配置好Docker的命令行环境。
  • Oracle VM Virtualbox - 虚拟机。

下载完成之后直接点击安装,安装成功后,桌边会出现三个图标,如下图所示:

3)启动 Docker

点击 Docker QuickStart 图标来启动 Docker Toolbox 终端。

如果系统显示 User Account Control 窗口来运行 VirtualBox 修改你的电脑,选择 Yes。

3)验证 Docker Desktop 是否安装成功

打开 PowerShell 输入指令后,打印以下信息则安装成功:

$ docker run hello-world

执行结果为:
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete 
Digest: sha256:f2266cbfc127c960fd30e76b7c792dc23b588c0db76233517e1891a4e357d519
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/

在 MacOS 系统上,常用的 Docker 安装方式有两种:使用 Homebrew 安装 和 使用 dmg 软件包安装。使用 Homebrew 安装:Homebrew 的Cask支持 Docker for Mac,因此可以很方便的使用 Homebrew Cask 来进行安装 Docker:brew install --cask --appdir=/Applications docker