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

Docker Swarm部署Windows容器:节点web.config文件复制问题求助

Solution for Per-Node web.config Deployment in Docker Swarm Windows Containers

Since you've already got your Docker Swarm cluster (1 manager + 5 workers) and Stack up and running, here's how to tweak your setup to copy each node's unique web.config into its corresponding Windows container:

1. Refine Your Entrypoint Script

Let's adjust your entrypoint.bat to handle the file copy before launching the container's core service. This script will take the node-specific web.config you mount and overwrite the default one in your website directory.

Here's a sample script (update paths to match your container's website root):

@echo off
echo Copying node-specific web.config to website directory...
copy "C:\mounted-config\web.config" "C:\inetpub\wwwroot\web.config" /Y
if %errorlevel% neq 0 (
    echo Error copying web.config! Exiting.
    exit /b %errorlevel%
)
echo Starting web service...
rem Replace this line with your container's original entrypoint command
"C:\ServiceMonitor.exe" w3svc

Skip deploying the script to every node by building a custom image based on your existing Windows container:

  1. Create a Dockerfile:
FROM your-existing-windows-image:tag
COPY entrypoint.bat C:\scripts\entrypoint.bat
ENTRYPOINT ["cmd", "/c", "C:\\scripts\\entrypoint.bat"]
  1. Build and push this image to your registry so all Swarm nodes can pull it.

Option B: Bind-Mount the Script from Each Node

If you don't want to rebuild the image, place entrypoint.bat at the same path on every worker node (e.g., C:\swarm-scripts\entrypoint.bat), then we'll mount it in the Stack compose.

2. Update Your Stack Compose File

Modify your docker-compose.yml to add a bind mount for the node-specific web.config and set the custom entrypoint:

version: "3.8"
services:
  your-web-service:
    image: your-custom-image:tag  # Use original image if using Option B
    deploy:
      replicas: 5
      placement:
        # Ensure one container runs per worker node (matches your per-node config need)
        constraints: [node.role == worker]
    volumes:
      # Mount the node's local web.config to a temporary container path
      - type: bind
        source: C:\path\on\node\web.config  # This path must exist on every worker node
        target: C:\mounted-config\web.config
        read_only: true
      # Only required for Option B (bind-mounting the entrypoint script)
      - type: bind
        source: C:\swarm-scripts\entrypoint.bat
        target: C:\scripts\entrypoint.bat
        read_only: true
    entrypoint: ["cmd", "/c", "C:\\scripts\\entrypoint.bat"]  # Omit if script is embedded in image
    # Add your existing service configs (ports, environment variables, etc.)

Key points:

  • The source path for web.config must be identical across all worker nodes—each node holds its own version of the file at this location.
  • The placement.constraints ensures one container per worker node, aligning with your per-node configuration requirement.

3. Deploy the Updated Stack

Run the standard Swarm deploy command to apply your changes:

docker stack deploy -c docker-compose.yml your-stack-name

4. Verify the Setup

To confirm the web.config was copied correctly, exec into a container on each node and check the file content:

# Replace <container-id> with your container's ID
docker exec -it <container-id> type C:\inetpub\wwwroot\web.config

You should see content matching the node's local web.config file.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 07:14:48