You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Docker Swarm在特定Windows节点部署需访问USB的SRV服务?

Got it, let's walk through this step by step—you need to deploy exactly one instance of your USB-dependent SRV service on each of your 5 Windows VMware nodes using Docker Swarm, replacing those manual restarts. Here's how to make this work seamlessly:

1. Prep: Get Docker Swarm Up on Your Windows Nodes

First, make sure every Windows node has Docker Desktop (or Docker Engine for Windows) installed and running. Then set up your Swarm cluster:

  • On your first node, initialize the Swarm:
    docker swarm init --advertise-addr <your-node-ip>
    
  • Copy the generated docker swarm join command that pops up, then run it on the remaining 4 nodes to add them to the cluster.
  • Verify the cluster is healthy:
    docker node ls
    
    You should see all 5 nodes listed with a "Ready" status.

2. Configure USB Access for the SRV Container

Since SRV needs access to the local USB device, Windows Docker requires a bit of setup to pass through USB devices to containers:

  • If using Docker Desktop: Go to Settings > Resources > Devices, then check the USB device(s) your SRV needs to access. This grants Docker permission to interact with the device.
  • If using Docker Engine (without Desktop): Use PowerShell's Get-PnpDevice command to find the full InstanceId of your USB device (it’ll look like \\.\USB#VID_1234&PID_5678#...#{a5dcbf10-6530-11d2-901f-00c04fb951ed}). You’ll need this path to mount the device into the container.

3. Write Your Swarm Compose File

Create a docker-compose.yml file—this is where you define how your SRV service gets deployed. The key here is using Swarm’s global mode to ensure one instance per node:

version: '3.8'
services:
  srv:
    image: your-srv-image:latest  # Replace with your actual SRV container image tag
    deploy:
      mode: global  # Critical! Deploys one instance on every matching node
      placement:
        constraints:
          - node.platform.os == windows  # Ensures we only deploy to Windows nodes
      restart_policy:
        condition: on-failure  # Auto-restarts the service if it crashes (goodbye manual restarts!)
    devices:
      # Replace with your USB device's InstanceId (from Get-PnpDevice)
      - "\\\\.\\USB#VID_1234&PID_5678#...#{a5dcbf10-6530-11d2-901f-00c04fb951ed}:\\\\.\\USB#VID_1234&PID_5678#...#{a5dcbf10-6530-11d2-901f-00c04fb951ed}"
    # Add any environment variables, ports, or volumes your SRV needs below
    environment:
      - SERVICE_ENV=production
    ports:
      - "8080:8080"  # Replace with your service's required port mapping

Pro tip: mode: global eliminates the need to manually target each node—Swarm handles deploying one instance to every node that meets your constraints automatically.

4. Deploy the Service to Swarm

On your Swarm manager node, run this command to deploy the service stack:

docker stack deploy -c docker-compose.yml srv-stack
  • Check the deployment status:
    docker stack services srv-stack
    
    You should see the REPLICAS column show 5/5 (one instance per node).
  • To verify instances are running on each node:
    docker node ps
    
    Each node will have an entry for srv-stack_srv.

5. Test & Maintain the Service

  • Validate USB access: Log into a container on any node and test the USB connection:
    docker exec -it <container-id> powershell
    # Run your SRV's USB test command here
    
  • Update the service: If you rebuild your SRV image, just re-run the docker stack deploy command—Swarm will roll out the update to all nodes automatically.
  • Restart all instances: No more manual restarts! Force a restart of all SRV containers with:
    docker service update --force srv-stack_srv
    

Quick Troubleshooting Tips

  • If USB isn’t accessible: Double-check Docker Desktop’s device permissions or that your InstanceId in the compose file is correct.
  • If a node doesn’t have an instance: Ensure the node is marked "Ready" in docker node ls and that the placement constraints match (e.g., it’s a Windows node).
  • Check logs: View logs for all SRV instances with:
    docker service logs srv-stack_srv
    

内容的提问来源于stack exchange,提问作者Erik

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 04:29:37