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

Dockerfile构建Python镜像失败:COPY无法找到requirements.txt

Fixing the "COPY failed: no such file or directory" Error for requirements.txt

Got it, let's break down why you're hitting this error and get your Docker build working again:

1. First, fix the typo in your Dockerfile

Looking at your Dockerfile, there's a clear typo in the COPY command:

COPY requirements.txt $PROJECT_DIR/requirments.txt

You misspelled requirements.txt as requirments.txt (missing an e) in the target path. Even better, since you've already set WORKDIR $PROJECT_DIR, you can simplify this line to avoid path typos entirely:

COPY requirements.txt ./

This will copy the file directly into your working directory (/var/www/coroner) without needing to type out the full path.

2. Double-check your build context

Your build command uses . as the context, meaning Docker looks for files in your current working directory. Even though you said you checked, let's confirm two things:

  • Run ls -l in your terminal to make sure requirements.txt is definitely present in the directory where you're running the docker build command.
  • If you have a .dockerignore file, open it and make sure it doesn't list requirements.txt or a wildcard like *.txt that would exclude the file from the build context.

3. Remove the redundant directory creation

Your Dockerfile runs RUN mkdir -p $PROJECT_DIR after setting WORKDIR $PROJECT_DIR—this is unnecessary because WORKDIR automatically creates the directory if it doesn't exist. Removing this line avoids any potential permission or directory structure issues.

Here's your corrected Dockerfile

FROM python:3.6.7-slim
# Version: 1.4
# Dockerfile to build the coroner container.
# Install Python and Package Libraries
RUN apt-get update && apt-get upgrade -y && apt-get autoremove && apt-get autoclean
RUN apt-get install -y \
libffi-dev \
libssl-dev \
default-libmysqlclient-dev \
libxml2-dev \
libxslt-dev \
libjpeg-dev \
libfreetype6-dev \
zlib1g-dev \
net-tools \
nano
ARG PROJECT=coroner
ARG PROJECT_DIR=/var/www/${PROJECT}
WORKDIR $PROJECT_DIR
ENV PYTHONUNBUFFERED 1
COPY requirements.txt ./
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
EXPOSE 8888
STOPSIGNAL SIGINT
ENTRYPOINT ["python", "manage.py"]
CMD ["runserver", "0.0.0.0:8888"]

If you're still stuck, try these extra steps

  • Explicitly specify the source file path in the COPY command: COPY ./requirements.txt ./ to leave no doubt where Docker should look.
  • Rebuild without cache to rule out old cached layers causing issues: sudo docker build --no-cache -t coroner:dev .
  • Check file permissions: Make sure requirements.txt has at least read permissions for others (run chmod 644 requirements.txt if needed) so Docker can access it.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.06 18:37:53