将 Azure API 管理自承载网关部署到 DockerDeploy an Azure API Management self-hosted gateway to Docker

本文提供将 Azure API 管理的自承载网关组件部署到 Docker 环境的步骤。This article provides the steps for deploying self-hosted gateway component of Azure API Management to a Docker environment.

备注

在 Docker 中托管自承载网关最适用于评估和开发用例。Hosting self-hosted gateway in Docker is best suited for evaluation and development use cases. 建议将 Kubernetes 用于生产用途。Kubernetes is recommended for production use. 请参阅文档以了解如何将自承载网关部署到 Kubernetes。See this document to learn how to deploy self-hosted gateway to Kubernetes.

先决条件Prerequisites

备注

自承载网关将打包为基于 x86-64 Linux 的 Docker 容器。Self-hosted gateway is packaged as a x86-64 Linux-based Docker container.

将自承载网关部署到 DockerDeploy the self-hosted gateway to Docker

  1. 选择“部署和基础结构”下的“网关” 。Select Gateways from under Deployment and infrastructure.
  2. 选择要部署的网关资源。Select the gateway resource you intend to deploy.
  3. 选择“部署”。Select Deployment.
  4. 请注意,“令牌”文本框中已使用默认“过期时间”和“机密密钥”值自动生成了访问令牌 。Note that an access token in the Token text box was autogenerated for you using the default Expiry and Secret key values. 如果需要,请在其中一个或两个控件中选择所需的值以生成新令牌。If needed, pick desired values in either or both controls to generate a new token.
  5. 确保在“部署脚本”下选择“Docker”。 Make sure Docker is selected under Deployment scripts.
  6. 选择“环境”旁边的“env.conf”链接以下载该文件。 Select env.conf file link next to the Environment to download the file.
  7. 选择“运行”文本框右侧的“复制”图标,将 Docker 命令复制到剪贴板 。Select copy icon located at the right end of the Run text box to copy the Docker command to clipboard.
  8. 将该命令粘贴到终端(或命令)窗口。Paste the command to the terminal (or command) window. 根据需要调整端口映射和容器名称。Adjust the port mappings and container name as needed. 请注意,该命令假定下载的环境文件位于当前目录中。Note that the command assumes that downloaded environment file is present in the current directory.
       docker run -d -p 80:8080 -p 443:8081 --name <gateway-name> --env-file env.conf mcr.microsoft.com/azure-api-management/gateway:<tag>
    
  9. 执行命令。Execute the command. 该命令指示 Docker 环境使用从 Microsoft 容器注册表下载的容器映像运行容器,并将该容器的 HTTP (8080) 和 HTTPS (8081) 端口映射到主机上的端口 80 和 443。The command instructs your Docker environment to run the container using container image downloaded from the Microsoft Container Registry, and to map the container's HTTP (8080) and HTTPS (8081) ports to ports 80 and 443 on the host.
  10. 运行以下命令来检查网关容器是否正在运行:Run the below command to check if the gateway container is running:
       docker ps
       CONTAINER ID        IMAGE                                                 COMMAND                  CREATED             STATUS              PORTS                                         NAMES
       895ef0ecf13b        mcr.microsoft.com/azure-api-management/gateway:latest   "/bin/sh -c 'dotnet …"   5 seconds ago       Up 3 seconds        0.0.0.0:80->8080/tcp, 0.0.0.0:443->8081/tcp   my-gateway
    
  11. 返回到 Azure 门户,单击“概述”并确认刚刚部署的自承载网关容器正在报告运行状况。Go back to Azure portal, click on Overview and confirm that self-hosted gateway container you just deployed is reporting a healthy status.

网关状态

提示

使用 console docker container logs 命令查看自承载网关日志的快照。Use console docker container logs command to view a snapshot of self-hosted gateway log.

使用 docker container logs --help 命令查看所有日志查看选项。Use docker container logs --help command to see all log viewing options.

后续步骤Next steps