设置 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 on Windows development machines. 设置本地 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 本机上运行。Linux-based Service Fabric clusters do not run natively on Windows. 为了运行本地 Service Fabric 群集,我们提供了预配置的 Docker 容器映像。To run a local Service Fabric cluster, a pre-configured Docker container image is provided. 准备事项:Before you get started, you need:

  • 至少 4 GB RAMAt least 4-GB RAM
  • 最新版的 DockerLatest version of Docker
  • Docker 必须在 Linux 模式下运行Docker must be running on Linux mode

Tip

  • 可以按照官方 Docker 文档中提及的步骤,在 Windows 上安装 Docker。You can follow the steps mentioned in the official Docker documentation to install Docker on your Windows.
  • 安装完以后,请按照此处提到的步骤验证其是否已正确安装。Once you are done installing, validate if it got installed properly following the steps mentioned here

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

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

  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"
    }
    

    建议的更新方法是:转到 Docker 图标 >“设置”>“守护程序”>“高级”,并在该处更新。The advised way to update is - go to Docker Icon > Settings > Daemon > Advanced and update it there. 接下来,请重启 Docker 守护程序来使更改生效。Next, restart the Docker daemon for the changes to take effect.

  2. 在新目录中创建名为 Dockerfile 的文件,以生成 Service Fabric 映像:In a new directory create a file called Dockerfile to build your Service Fabric Image:

    FROM mcr.microsoft.com/service-fabric/onebox:latest
    WORKDIR /home/ClusterDeployer
    RUN ./setup.sh
    #Generate the local
    RUN locale-gen en_US.UTF-8
    #Set environment variables
    ENV LANG=en_US.UTF-8
    ENV LANGUAGE=en_US:en
    ENV LC_ALL=en_US.UTF-8
    EXPOSE 19080 19000 80 443
    #Start SSH before running the cluster
    CMD /etc/init.d/ssh start && ./run.sh
    

    Note

    可以修改此文件,以便在容器中添加更多程序或依赖项。You can adapt this file 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.

    Tip

    默认情况下,这样会拉取具有最新 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

  3. 若要通过 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 .
    

    Note

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

  4. 现在,每当有需要时,都可以运行以下命令,快速启动 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
    

    Tip

    为容器实例提供一个名称,以更具可读性的方式对其进行处理。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 19080:19080 -p 8080:8080 --name sfonebox mcr.microsoft.com/service-fabric/onebox:latest

  5. 群集需要一小段时间来启动,可以使用以下命令查看日志,或者通过 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
    
  6. 成功完成步骤 5 之后,即可从 Windows 转到 http://localhost:19080,然后便会看到 Service Fabric 资源管理器。After step 5 is completed successfully, you can go to http://localhost:19080 from your Windows and you would be able to see the Service Fabric explorer. 此时,可使用 Windows 开发人员计算机上的任何工具连接到此群集,并部署面向 Linux Service Fabric 群集的应用程序。At this point, you can connect to this cluster using any tools from your Windows developer machine and deploy application targeted for Linux Service Fabric clusters.

    Note

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

  7. 完成后,可使用以下命令来停止并清理容器:When you are done, stop and cleanup 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 服务无法运行且不受支持 问题 #132DNS service does not run and is not supported Issue #132

后续步骤Next steps