Dockerfile COPY指令显式引用文件失败,Heroku容器构建报错
Project Structure
├── compose │ ├── local │ │ └── django │ │ ├── Dockerfile │ │ ├── celery │ │ │ ├── beat │ │ │ │ └── start.sh │ │ │ └── worker │ │ │ └── start.sh │ │ └── start.sh │ └── production │ ├── caddy │ │ ├── Caddyfile │ │ └── Dockerfile.caddy │ └── django │ └── Dockerfile.django
Issue
When running $ heroku container:push --recursive from the root directory, the build fails with an error starting with:
Sending build context to Docker daemon 3.072kB
Step 1/2 : FROM abiosoft/caddy:0.10.6...
Root Causes & Fixes
1. Non-Standard Dockerfile Names Are Not Detected by --recursive
Heroku's --recursive flag scans directories for files named exactly Dockerfile—it won't automatically pick up Dockerfile.caddy or Dockerfile.django.
Fix:
Either:
- Rename your custom Dockerfiles to
Dockerfile(e.g., renameDockerfile.caddytocompose/production/caddy/Dockerfile), then re-runheroku container:push --recursive. - Or push each service individually with the
--fileflag to specify the custom Dockerfile:# Push Django production service heroku container:push web --file compose/production/django/Dockerfile.django # Push Caddy service heroku container:push caddy --file compose/production/caddy/Dockerfile.caddy
2. Outdated/Unavailable Caddy Image
The abiosoft/caddy:0.10.6 image is extremely old (released in 2018) and has likely been removed from Docker Hub, causing a pull failure during build.
Fix:
Replace the outdated base image in Dockerfile.caddy with the official, actively maintained Caddy image. For example, use the latest Alpine-based stable build:
# Replace this line # FROM abiosoft/caddy:0.10.6 # With this FROM caddy:2-alpine
You can adjust the tag to match your needs (e.g., caddy:2.7-alpine for a specific minor version).
3. Build Context Path Mismatches
When running the push from the root directory, the Docker build context is the root folder. If your Dockerfiles use COPY/ADD commands that reference paths relative to the Dockerfile's directory, those paths will break because Docker looks for files relative to the build context (root).
Fix:
Update all COPY/ADD commands in your Dockerfiles to use paths relative to the root directory. For example, in Dockerfile.caddy, instead of:
COPY Caddyfile /etc/caddy/Caddyfile
Use:
COPY compose/production/caddy/Caddyfile /etc/caddy/Caddyfile
内容的提问来源于stack exchange,提问作者Jay Jung

