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

.NET Aspire中解决postgresml容器镜像自动退出问题

在.NET Aspire中配置PostgresML镜像时容器自动退出的解决方案

问题场景

使用.AddPostgres().WithImage(...)引入PostgresML镜像时,容器启动后会自动退出。直接通过docker run命令并添加-it参数可以正常运行容器,但在.NET Aspire中配置后,容器始终处于退出状态。

PostgresML官方提供的正常运行命令:

docker run \
    -it \
    -v postgresml_data:/var/lib/postgresql \
    -p 5433:5432 \
    -p 8000:8000 \
    ghcr.io/postgresml/postgresml:2.7.12 \
    sudo -u postgresml psql -d postgresml

我的.NET Aspire配置代码(无法阻止容器退出):

postgres = builder.AddPostgres("lcommerce-dependency-postgres", port: 5432)
        .WithImage("postgresml/postgresml")
        .WithImageTag("2.9.3")
        .WithImageRegistry("ghcr.io")
        .WithHttpEndpoint(name: "endpoint-55432-5432",
            port: 8000, targetPort: 8000, isProxied: true)
        .WithContainerRuntimeArgs("-it", "--gpus=all");

尝试通过.WithContainerRuntimeArgs("-it", "--gpus=all")保持容器运行但无效,且已确认.NET Aspire默认添加的用户名密码无问题(pgvector/pgvector镜像可正常运行)。

临时解决方案

以下两种临时方案可解决容器退出问题:

方案1:模拟官方命令的启动参数

.WithContainerRuntimeArgs("-i", "--gpus=all")
.WithArgs("sudo", "-u", "postgresml", "psql", "-d", "postgresml")

方案2:用sleep infinity维持容器运行

.WithContainerRuntimeArgs("--gpus=all")
.WithArgs("sleep","infinity")

正确解决方案

不建议依赖临时方案,正确做法是创建自定义镜像,将Postgres数据库服务设置为容器的主持久进程,从根本上解决容器退出问题。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 16:19:59