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

ECS混合部署Dagster Cloud容器报错:dagster可执行文件未找到

问题

尝试在Dagster Cloud的ECS混合部署模型中创建容器,已成功推送容器至Dagster,但持续出现以下错误:

dagster_cloud.workspace.ecs.client.EcsServiceError: ECS service failed because task arn:aws:ecs:ap-northeast-1:*****:task/Dagster-Cloud-my-cluster-Cluster/1d151e6d40b44588a4ed4446a949d44a failed: CannotStartContainerError: ResourceInitializationError: failed to create new container runtime task: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "dagster": executable file not found in $PATH: unknown

Task logs:
runc create failed: unable to start container process: exec: "dagster": executable file not found in $PATH

For more information about the failure, check the ECS console for logs for task arn:aws:ecs:ap-northeast-1:*****:task/Dagster-Cloud-my-cluster-Cluster/1d151e6d40b44588a4ed4446a949d44a in cluster Dagster-Cloud-my-cluster-Cluster.
  File "/dagster-cloud/dagster_cloud/workspace/user_code_launcher/user_code_launcher.py", line 1304, in _reconcile
    self._wait_for_new_server_ready(
  File "/dagster-cloud/dagster_cloud/workspace/ecs/launcher.py", line 458, in _wait_for_new_server_ready
    task_arn = self.client.wait_for_new_service(
  File "/dagster-cloud/dagster_cloud/workspace/ecs/client.py", line 491, in wait_for_new_service
    return self.check_service_has_running_task(
  File "/dagster-cloud/dagster_cloud/workspace/ecs/client.py", line 607, in check_service_has_running_task
    self._raise_failed_task(task, container_name, logger)
  File "/dagster-cloud/dagster_cloud/workspace/ecs/client.py", line 526, in _raise_failed_task
    raise EcsServiceError(

Docker容器配置如下:

###############################################################################
# Base container
###############################################################################
FROM python:3.11 AS base

# Define the environment variables necessary to work with poetry
ENV POETRY_VERSION=1.5.1 \
  POETRY_HOME="/opt/poetry" \
  POETRY_VIRTUALENVS_IN_PROJECT=true \
  POETRY_NO_INTERACTION=1

# Add the poetry bin to our path
ENV PATH="$POETRY_HOME/bin:$PATH"

###############################################################################
# Poetry installer container
###############################################################################
FROM base AS installer

# Install poetry
RUN curl -sSL https://install.python-poetry.org | python3 -

###############################################################################
# Container that actually builds the application
###############################################################################
FROM base AS builder

# Copy the poetry files from the poetry installer to this container
COPY --from=installer $POETRY_HOME $POETRY_HOME

# Describe the environment variables necessary to install our dependencies
ENV PYTHONFAULTHANDLER=1 \
  PYTHONUNBUFFERED=1 \
  PYTHONHASHSEED=random \
  PIP_NO_CACHE_DIR=off \
  PIP_DISABLE_PIP_VERSION_CHECK=on \
  PIP_DEFAULT_TIMEOUT=100

# Set the working directory to one we can install to easily
WORKDIR /app

# Copy the poetry.lock and pyproject.toml files first to ensure that dependencies
# are only installed when they're updated
COPY poetry.lock pyproject.toml /app/

# Copy in our SSH key so we can retrieve the shared GitHub repo
RUN mkdir -p -m 0700 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts

# Install our project dependencies
RUN --mount=type=ssh poetry install --only dagster --no-ansi --no-root

# Build the project
COPY . /app/
RUN poetry build

###############################################################################
# Create a runtime environment that's much smaller
###############################################################################
FROM python:3.11-alpine AS runtime

# Set the working directory to where Dagster will look for the application
WORKDIR /opt/dagster/app

# Copy the project wheel file
COPY --from=builder /app/dist/*.whl /

# Install the wheel file using pip and then install dagster and dagster-cloud
RUN pip install --no-cache-dir /*.whl \
  && rm -rf /*.whl

包的pyproject.toml依赖项:

[tool.poetry.group.dagster.dependencies]
dagster = "^1.5.9"
dagster-aws = "^0.21.9"
pendulum = "^2.1.2"
pandas = "^2.1.3"
openpyxl = "^3.1.2"
dagster-cloud = "^1.5.12"

按配置dagster和dagster-cloud应已安装,但未生效,求排查问题。


解决方案

核心问题是构建流程中Dagster依赖未被正确打包到最终镜像,具体原因和修复步骤如下:

1. Poetry组依赖未被包含进Wheel包

你的dagster相关依赖放在了Poetry的dagster组下,而Poetry默认不会将组依赖添加到Wheel包的install_requires声明中。这导致在runtime阶段安装Wheel时,pip只会安装项目本身,不会自动拉取dagster、dagster-cloud等依赖,最终容器中没有dagster可执行文件。

修复方式(二选一):

  • 方式一:将组依赖移到主依赖区
    修改pyproject.toml,把dagster组的依赖移到[tool.poetry.dependencies]下:
    [tool.poetry.dependencies]
    python = "^3.11"
    dagster = "^1.5.9"
    dagster-aws = "^0.21.9"
    pendulum = "^2.1.2"
    pandas = "^2.1.3"
    openpyxl = "^3.1.2"
    dagster-cloud = "^1.5.12"
    
  • 方式二:配置组依赖被包含进Wheel
    保留组结构,但添加配置让Poetry将组依赖打包进Wheel:
    [tool.poetry.group.dagster]
    optional = false
    include = ["*"]
    
    [tool.poetry.group.dagster.dependencies]
    dagster = "^1.5.9"
    dagster-aws = "^0.21.9"
    pendulum = "^2.1.2"
    pandas = "^2.1.3"
    openpyxl = "^3.1.2"
    dagster-cloud = "^1.5.12"
    

2. 改用虚拟环境复制的构建方式(更可靠)

如果不想调整依赖结构,可以直接将builder阶段的虚拟环境复制到runtime镜像,确保所有依赖完整保留:

# 替换原runtime阶段代码
FROM python:3.11-alpine AS runtime

WORKDIR /opt/dagster/app

# 复制builder阶段的虚拟环境
COPY --from=builder /app/.venv /app/.venv

# 将虚拟环境的bin目录加入系统PATH
ENV PATH="/app/.venv/bin:$PATH"

# 复制项目代码
COPY --from=builder /app /opt/dagster/app

3. 验证可执行文件路径

可以在runtime阶段添加调试命令,确认dagster是否安装且在PATH中:

RUN echo $PATH && ls -la /usr/local/bin/dagster || ls -la /app/.venv/bin/dagster

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.04 00:34:51