设置 Windows 开发人员计算机上的 Linux Service Fabric 群集Set up a Linux Service Fabric cluster on your Windows developer machine

本文档介绍如何在 Windows 开发计算机上设置本地 Linux Service Fabric 群集。This document covers how to set up a local Linux Service Fabric cluster on a Windows development machine. 设置本地 Linux 群集有助于快速测试在 Windows 计算机上开发的面向 Linux 群集的应用程序。Setting up a local Linux cluster is useful to quickly test applications targeted for Linux clusters but are developed on a Windows machine.

先决条件Prerequisites

基于 Linux 的 Service Fabric 群集不在 Windows 上运行,但为了实现跨平台原型设计,我们提供了一个可以通过用于 Windows 的 Docker 进行部署的 Linux Service Fabric 单机群集 Docker 容器。Linux-based Service Fabric clusters do not run on Windows, but to enable cross-platform prototyping we have provided a Linux Service Fabric one box cluster docker container, which may be deployed via Docker for Windows.

准备事项:Before you get started, you need:

提示

若要在 Windows 计算机上安装 Docker,请按 Docker 文档中的步骤操作。To install Docker on your Windows machine, follow the steps in the Docker documentation. 安装之后,请验证安装After installing, verify your installation.

创建本地容器和设置 Service FabricCreate a local container and setup Service Fabric

若要设置本地 Docker 容器并在其上运行 Service Fabric 群集,请运行以下步骤:To set up a local Docker container and have a Service Fabric cluster running on it, run the following steps:

  1. 使用以下内容更新主机上的 Docker 守护程序配置并重启 Docker 守护程序:Update the Docker daemon configuration on your host with the following and restart the Docker daemon:

    {
      "ipv6": true,
      "fixed-cidr-v6": "2001:db8:1::/64"
    }
    

    建议的更新方法是转到:The advised way to update is to go to:

    • Docker 图标 >“设置”>“Docker 引擎”Docker Icon > Settings > Docker Engine
    • 添加上面列出的新字段Add the new fields listed above
    • 应用和重启 - 重启 Docker 守护程序以使更改生效。Apply & Restart - restart the Docker daemon for the changes to take effect.
  2. 通过 PowerShell 启动群集。Start the cluster via PowerShell.
    Ubuntu 18.04 LTS:Ubuntu 18.04 LTS:

    docker run --name sftestcluster -d -v /var/run/docker.sock:/var/run/docker.sock -p 19080:19080 -p 19000:19000 -p 25100-25200:25100-25200 mcr.microsoft.com/service-fabric/onebox:u18
    

    Ubuntu 16.04 LTS:Ubuntu 16.04 LTS:

    docker run --name sftestcluster -d -v /var/run/docker.sock:/var/run/docker.sock -p 19080:19080 -p 19000:19000 -p 25100-25200:25100-25200 mcr.microsoft.com/service-fabric/onebox:u16
    

    提示

    默认情况下,这样会拉取具有最新 Service Fabric 版本的映像。By default, this will pull the image with the latest version of Service Fabric. 对于特定的修订版本,请参阅 Docker Hub 上的 Service Fabric Onebox 页。For particular revisions, see the Service Fabric Onebox page on Docker Hub.

  3. 可选:构建扩展的 Service Fabric 映像。Optional: Build your extended Service Fabric image.

    在新目录中创建名为 Dockerfile 的文件,以构建自定义映像:In a new directory, create a file called Dockerfile to build your customized image:

    备注

    可以使用 Dockerfile 修改上面的映像,以将其他程序或依赖项添加到容器中。You can adapt the image above with a Dockerfile to add additional programs or dependencies into your container. 例如,添加 RUN apt-get install nodejs -y 可以支持将 nodejs 应用程序用作来宾可执行文件。For example, adding RUN apt-get install nodejs -y will allow support for nodejs applications as guest executables.

    FROM mcr.microsoft.com/service-fabric/onebox:u18
    RUN apt-get install nodejs -y
    EXPOSE 19080 19000 80 443
    WORKDIR /home/ClusterDeployer
    CMD ["./ClusterDeployer.sh"]
    

    提示

    默认情况下,这样会拉取具有最新 Service Fabric 版本的映像。By default, this will pull the image with the latest version of Service Fabric. 如需特定的修订版本,请访问 Docker 中心页。For particular revisions, please visit the Docker Hub page.

    若要通过 Dockerfile 生成可重用的映像,请打开终端并将 cd 切换到 Dockerfile 所在的目录,然后运行:To build your reusable image from the Dockerfile, open a terminal and cd to the directly holding your Dockerfile then run:

    docker build -t mysfcluster .
    

    备注

    此操作需要一段时间,但只需执行一次。This operation will take some time but is only needed once.

    现在,每当有需要时,都可以运行以下命令,快速启动 Service Fabric 的本地副本:Now you can quickly start a local copy of Service Fabric whenever you need it by running:

    docker run --name sftestcluster -d -v /var/run/docker.sock:/var/run/docker.sock -p 19080:19080 -p 19000:19000 -p 25100-25200:25100-25200 mysfcluster
    

    提示

    为容器实例提供一个名称,以更具可读性的方式对其进行处理。Provide a name for your container instance so it can be handled in a more readable manner.

    如果应用程序正在侦听特定端口,则必须使用附加的 -p 标记指定这些端口。If your application is listening on certain ports, the ports must be specified by using additional -p tags. 例如,如果应用程序正在侦听端口 8080,请添加下面的 -p 标记:For example, if your application is listening on port 8080, add the following -p tag:

    docker run -itd -p 19000:19000 -p 19080:19080 -p 8080:8080 --name sfonebox mcr.microsoft.com/service-fabric/onebox:u18

  4. 群集需要一小段时间来启动,可以使用以下命令查看日志,或者通过 http://localhost:19080 跳转到仪表板来查看群集运行状况:The cluster will take a short amount of time to start, you can view logs using the following command or jump to the dashboard to view the clusters health http://localhost:19080:

    docker logs sftestcluster
    
  5. 按照步骤 4 的说明成功部署群集后,可以从 Windows 计算机转到 http://localhost:19080,以找到 Service Fabric Explorer 仪表板。After the cluster is deployed successfully as observed in step 4, you can go to http://localhost:19080 from your Windows machine to find the Service Fabric Explorer dashboard. 此时,可使用 Windows 开发人员计算机上的工具连接到此群集,并部署面向 Linux Service Fabric 群集的应用程序。At this point, you can connect to this cluster using tools from your Windows developer machine and deploy applications targeted for Linux Service Fabric clusters.

    备注

    Windows 当前不支持 Eclipse 插件。The Eclipse plugin is currently not supported on Windows.

  6. 完成后,可使用以下命令来停止并清理容器:When you are done, stop and clean up the container with this command:

    docker rm -f sftestcluster
    

已知限制Known Limitations

以下是在 Mac 的容器中运行的本地群集的已知限制:The following are known limitations of the local cluster running in a container for Mac's:

  • DNS 服务未运行,且目前在容器中不受支持。DNS service does not run and is currently not supported within the container. 问题 #132Issue #132
  • 运行基于容器的应用需要在 Linux 主机上运行 SF。Running container-based apps requires running SF on a Linux host. 当前不支持嵌套容器应用。Nested container apps are currently not supported.

后续步骤Next steps