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

使用VSCode+Docker开发Python应用遇文件找不到错误求助

问题:Docker运行Python应用时出现FileNotFoundError

运行容器时出现以下错误:

FileNotFoundError: [Errno 2] No such file or directory: '/app/spotify-2-mp3\main.py'

我的Dockerfile内容:

FROM python

# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE=1

# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED=1
WORKDIR /app
# Install pip requirements
COPY . .
RUN python -m pip install -r requirements.txt

# Creates a non-root user with an explicit UID and adds permission to access the /app folder
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
USER appuser

# During debugging, this entry point will be overridden.
CMD ["python", "spotify-2-mp3/main.py"]

目录结构:

目录结构截图


解决方案:

从目录结构可见,main.py直接位于项目根目录下,并非spotify-2-mp3子文件夹内。Dockerfile中的COPY . .已将项目根目录的所有文件复制到容器的/app目录,因此/app下直接存在main.py,无需额外的子目录路径。

修改Dockerfile里的CMD指令,将路径改为直接指向main.py:

CMD ["python", "main.py"]

重新构建镜像并运行容器即可解决该错误。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.07 21:05:25