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

Docker Compose启动Windows Server容器后立即退出问题排查

问题解决:Windows Server容器通过Docker Compose启动后立即退出/找不到文件报错

问题原因

你的Docker Compose中entrypoint的配置格式错误。当使用数组格式定义entrypoint时,必须将命令和每个参数拆分为单独的数组元素,而你把整个命令行作为单个字符串传入,Docker会尝试寻找名为cmd.exe /c ping -t localhost的可执行文件,这显然不存在,因此抛出"系统找不到指定文件"的错误。

正确的Docker Compose配置

你可以选择以下两种正确的写法:

写法1:数组格式(推荐,参数清晰)

services:
  testserver:
    image: mcr.microsoft.com/windows/server:ltsc2022
    container_name: testserver
    entrypoint: ["cmd.exe", "/c", "ping", "-t", "localhost"]

写法2:shell格式(更贴近docker run的命令写法)

services:
  testserver:
    image: mcr.microsoft.com/windows/server:ltsc2022
    container_name: testserver
    entrypoint: cmd.exe /c ping -t localhost

验证效果

使用以上任意一种配置启动容器后,容器会持续运行ping -t localhost命令,不会立即退出,和你用docker run命令的效果完全一致。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 11:10:15