# 什么是 Docker

在 Edgegap，我们使用容器在全球范围内均匀分配负载。我们需要让你的游戏在毫秒内启动，因此容器需要从速度出发并据此构建。我们将引导你创建一个 Docker 镜像，也称为容器。

{% hint style="info" %}
如果你想快速熟悉容器，我们强烈推荐 [这段快速视频](https://www.youtube.com/watch?v=J0NuOlA2xDc\&ab_channel=Coderized).
{% endhint %}

<figure><img src="/files/51168a14244414c35eaa8c726275b9b520f6df1d" alt=""><figcaption></figcaption></figure>

### **什么是 Docker？**

* Docker 是一种 PaaS（平台即服务），允许进行操作系统级虚拟化。

### **什么是 Docker Run 命令？**

* docker run 命令允许从镜像创建一个容器，以便 Docker 桌面引擎可以运行该容器。

### **试一试**

让我们先添加你在电脑上创建第一个容器所需要的工具。

你可以按照 Docker desktop 上说明的安装步骤进行。

如果你正在运行 [Windows 10 专业版](https://docs.docker.com/docker-for-windows/install/) 如果你正在运行 [Windows 10 家庭版](https://docs.docker.com/docker-for-windows/install-windows-home/) 如果你正在运行 [macOS](https://docs.docker.com/docker-for-mac/install/)

现在你已经在本地机器上运行 Docker，我们可以从一个简单的 hello world 开始。

```sh
docker run -d -p 80:80 --name speedtest edgegap/speedtest-edge
```

你可以打开命令提示符并输入上面的命令。

这些步骤将自动继续。

1. 从 Edgegap 仓库下载容器（仅限第一次）
2. 启动容器
3. 名称将是 speedtest（--name）
4. 要暴露你的容器，你需要在 docker run 命令中进行设置。在这个例子中，我们会将外部的 80 端口映射到容器中暴露的 80 端口（-p）
5. 你可以在网页浏览器中访问并输入 [http://localhost](http://localhost/)
6. 好了，你已经运行了你的第一个容器。

现在你已经让容器运行起来了，你可以与它交互。我们将在下一节中重新启动容器、停止它，并查看它的网络。首先，你需要在命令行中本地查看 Docker 引擎上正在运行的内容，输入。

```sh
docker ps
```

你应该也会看到类似的内容。

```
容器 ID        镜像                    命令                  创建时间            状态              端口                名称
dbf4d3734111        edgegap/speedtest-edge   "docker-php-entrypoi…"   29 分钟前      运行 29 分钟       0.0.0.0:80->80/tcp   speedtest
```

你可以直观看到在你电脑上运行的容器信息；这个列表中可以有不止一个正在运行的容器。

`docker ps` 是一个简单的命令；你会经常学到并使用它。

假设你需要了解更多关于正在运行的容器的信息。你可以通过运行以下命令，让 docker 引擎提供有关你的容器的所有详细信息：

```sh
docker container inspect speedtest
```

如果你想查看 docker 引擎创建的内部网络，可以通过运行以下命令来实现。

```sh
docker network ls
```

你会得到类似这样的结果：

```
网络 ID          名称                驱动              范围
67b24038b9ca        bridge              bridge              local
6f7fe43a489d        host                host                local
3d80cdb86a7e        none                null                local
```

如果你想进一步深入了解网络配置，可以运行以下命令：

```sh
docker network inspect 67b24038b9ca
# 其中 678b24038b9ca 是与你的容器相连的网络
```

Docker 停止

现在你已经启动了容器，可以使用以下命令停止它：

```sh
docker container stop speedtest
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.edgegap.com/zh/docs/tools-and-integrations/container/docker.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
