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

执行docker compose up时出现路径找不到错误的求助

问题描述

执行命令:

docker compose up

出现错误:

docker:desktop-linux unable to prepare context: path "" not found

确认当前处于正确目录,服务之前可正常运行,执行docker compose down后无法启动,移动yaml及配套文件夹无效。

docker-compose.yaml 内容

version: '3'

services:
  source_postgres:
    image: postgres:latest
    ports:
      - "5433:5432"
    networks:
      - elt_network
    environment:
      POSTGRES_DB: source_db
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: secret
    volumes:
      - ./source_db_init/init.sql:/docker-entrypoint-initdb.d/init.sql

  destination_postgres:
    image: postgres:latest
    ports:
      - "5434:5432"
    networks:
      - elt_network
    environment:
      POSTGRES_DB: destination_db
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: secret

  elt_script:
    build:
      context: ./elt_script # Directory containing the Dockerfile and elt_script.py
      dockerfile: Dockerfile # Name of the Dockerfile, if it's something other than "Dockerfile", specify here
    command: [ "python", "elt_script.py" ]
    networks:
      - elt_network
    depends_on:
      - source_postgres
      - destination_postgres

networks:
  elt_network:
    driver: bridge

目录结构

~/docker_tutorial/ELT » tree                                                                       nita@caro
.
├── docker-compose.yaml
├── elt
│   ├── Dockerfile.webloc
│   └── elt_script.py
└── source_db_init
    └── init.sql

3 directories, 4 files
问题排查与修复

直接看目录结构和yaml配置就能找到问题:

  1. 构建路径不匹配:yaml里elt_script服务的context写的是./elt_script,但实际存放代码的目录是./elt,路径写错了。
  2. Dockerfile文件名不对:实际目录里的文件是Dockerfile.webloc(这是macOS的网页快捷方式格式,大概率是误操作生成的),但yaml里指定的是Dockerfile,找不到对应文件。

修复步骤二选一即可:

  • 方法一:修改docker-compose.yaml的elt_script配置,匹配实际路径和文件名:
    elt_script:
      build:
        context: ./elt
        dockerfile: Dockerfile.webloc
      # 其余配置保持不变
    
  • 方法二(更规范):把elt/Dockerfile.webloc重命名为elt/Dockerfile,然后yaml里的build部分可以简化成:
    elt_script:
      build: ./elt
      # 其余配置保持不变
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.30 15:23:12