Docker 简明教程

Docker - Toolbox

在介绍性章节中,我们已经看到了在 Windows 上安装 Docker 工具箱。开发 Docker 工具箱的目的是可以在 Windows 和 MacOS 上运行 Docker 容器。Windows 工具箱的站点是 https://docs.docker.com/docker-for-windows/

In the introductory chapters, we have seen the installation of Docker toolbox on Windows. The Docker toolbox is developed so that Docker containers can be run on Windows and MacOS. The site for toolbox on Windows is https://docs.docker.com/docker-for-windows/

toolbox on windows

对于 Windows,你需要拥有启用了 Hyper-V 的 Windows 10 或 Windows Server 2016。

For Windows, you need to have Windows 10 or Windows Server 2016 with Hyper-V enabled.

工具箱包括以下组件 -

The toolbox consists of the following components −

  1. Docker Engine − This is used as the base engine or Docker daemon that is used to run Docker containers.

  2. Docker Machine − for running Docker machine commands.

  3. Docker Compose for running Docker compose commands.

  4. Kinematic − This is the Docker GUI built for Windows and Mac OS.

  5. Oracle virtualbox

现在我们来讨论使用 Docker 工具箱可以进行的不同类型的活动。

Let’s now discuss the different types of activities that are possible with Docker toolbox.

Running in Powershell

使用 Windows 10 中的 Docker 工具箱,您现在可以在 powershell 中运行 Docker 命令。如果您在 Windows 上打开 powershell 并输入 Docker 版本的命令,您将获得有关所安装 Docker 版本的所有必需的详细信息。

With Docker toolbox on Windows 10, you can now run Docker commands off powershell. If you open powershell on Windows and type in the command of Docker version, you will get all the required details about the Docker version installed.

windows powershell

Pulling Images and Running Containers

您现在也可以从 Docker Hub 中拉取映像,并在 powershell 中运行容器,就像在 Linux 中所做的那样。以下示例将简要展示从 Ubuntu 映像下载和从该映像运行容器的过程。

You can also now pull Images from Docker Hub and run containers in powershell as you would do in Linux. The following example will show in brief the downloading of the Ubuntu image and running of the container off the image.

第一步是使用 Docker pull 命令从 Docker Hub 中拉取 Ubuntu 映像。

The first step is to use the Docker pull command to pull the Ubuntu image from Docker Hub.

pulling images

下一步是使用以下 run 命令运行 Docker 映像 −

The next step is to run the Docker image using the following run command −

docker run –it ubuntu /bin/bash

您会注意到该命令与 Linux 中的命令相同。

You will notice that the command is the same as it was in Linux.

same command

Kitematic

这是 Windows 上 Docker 的 GUI 等效项。要打开此 GUI,请转到任务栏,在 Docker 图标上右键单击并选择打开 Kitematic。

This is the GUI equivalent of Docker on Windows. To open this GUI, go to the taskbar and on the Docker icon, right-click and choose to open Kitematic.

kitematic

它会提示您下载 Kitematic GUI。下载后,只需解压内容。将有一个名为 Kitematic.exe 的文件。双击此 exe 文件以打开 GUI 界面。

It will prompt you to download Kitematic GUI. Once downloaded, just unzip the contents. There will be a file called Kitematic.exe. Double-click this exe file to open the GUI interface.

然后,它将要求您登录 Docker Hub,通过 GUI 输入用户名和密码即可。只需输入必需的用户名和密码,然后单击登录按钮。

You will then be requested to log into Docker Hub, enter through the GUI. Just enter the required username and password and then click the Login button.

connect to docker hub

登录后,您将能够看到界面左侧系统上下载的所有映像。

Once logged in, you will be able to see all the images downloaded on the system on the left-hand side of the interface.

images downloaded

在右侧,您将找到 Docker Hub 上提供的所有映像。

On the right-hand side, you will find all the images available on Docker Hub.

我们来举一个例子来了解如何使用 Kitematic 从 Docker Hub 下载 Node 映像。

Let’s take an example to understand how to download the Node image from Docker Hub using Kitematic.

Step 1 - 在搜索条件中输入 node 关键字。

Step 1 − Enter the keyword of node in the search criteria.

keyword of node

Step 2 - 单击官方 Node 映像上的 create 按钮。然后,您将看到正在下载该映像。

Step 2 − Click the create button on official Node image. You will then see the image being downloaded.

create button

映像下载完成后,它将开始运行 Node 容器。

Once the image has been downloaded, it will then start running the Node container.

node container

Step 3 - 如果您转到 settings 选项卡,您可以向下钻取到进一步的设置选项,如下所示。

Step 3 − If you go to the settings tab, you can drill-down to further settings options, as shown below.

  1. General settings − In this tab, you can name the container, change the path settings, and delete the container.

general settings
  1. Ports − Here you can see the different port mappings. If you want, you can create your own port mappings.

ports
  1. Volumes − Here you can see the different volume mappings.

volumes
  1. Advanced − It contains the advanced settings for the container.

advanced