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

将指定Docker run命令转换为适配Docker Swarm的docker-compose.yml

Got it, let's translate that docker run command into a clean docker-compose.yml file that works perfectly with Docker Swarm. Here's the breakdown:

The Docker Compose File

First, create a docker-compose.yml with this content:

version: '3.8'

services:
  stress-test:
    # Specify the same image from your docker run command
    image: progrium/stress
    # Pass all the stress test arguments as the container's startup command
    command: --cpu 2 --io 1 --vm 2 --vm-bytes 128M --timeout 10s
    # Match the --rm behavior: tell Swarm not to restart the container after it exits
    deploy:
      restart_policy:
        condition: none
    # Optional: Uncomment these if you need interactive terminal support (from -it flag)
    # stdin_open: true
    # tty: true

What Each Part Does

Let's map this back to your original docker run command:

  • image: progrium/stress: Directly corresponds to the image you specified in docker run
  • command: ...: This replaces everything after the image name in your original command — all the stress test parameters get passed directly to the container
  • deploy.restart_policy.condition: none: This replicates the --rm behavior by ensuring Swarm doesn't restart the container once it finishes the stress test (and Swarm will automatically clean up the container after exit)
  • The stdin_open and tty lines: These correspond to the -it flags in your original command. Most of the time, you won't need these for a one-off stress test in Swarm (since the test runs and exits on its own), but uncomment them if you need to attach an interactive terminal to the container.

Running It in Docker Swarm

To deploy this as a Swarm service, run:

docker stack deploy -c docker-compose.yml stress-test-stack

If you want a more "one-off" execution (closer to the original docker run --rm), you can also use:

docker-compose run --rm stress-test

Note: The above runs the task locally via Docker Compose. If you need to run it directly on the Swarm cluster as a one-off task, you could also use docker service create --rm, but the Compose file gives you a reusable configuration.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 08:08:08