Skip to content

Heredocs in COPY statement throws docker.errors.BuildError: COPY failed: no source files were specified #3273

Open
@minhio

Description

@minhio

Given the the following Dockerfile

FROM alpine

COPY <<-EOT /tmp/hello
    Hello, world!
EOT

and the following Python codes for building the image

import docker

client = docker.from_env()
image, _ = client.images.build(path='.', dockerfile='Dockerfile')

resulted in this error

docker.errors.BuildError: COPY failed: no source files were specified

client version

{
    "Platform": {"Name": "Docker Engine - Community"},
    "Components": [
        {
            "Name": "Engine",
            "Version": "27.0.1",
            "Details": {
                "ApiVersion": "1.46",
                "Arch": "amd64",
                "BuildTime": "2024-06-24T14:57:52.000000000+00:00",
                "Experimental": "false",
                "GitCommit": "ff1e2c0",
                "GoVersion": "go1.21.11",
                "KernelVersion": "5.15.133.1-microsoft-standard-WSL2",
                "MinAPIVersion": "1.24",
                "Os": "linux",
            },
        },
        {
            "Name": "containerd",
            "Version": "1.7.18",
            "Details": {"GitCommit": "ae71819c4f5e67bb4d5ae76a6b735f29cc25774e"},
        },
        {
            "Name": "runc",
            "Version": "1.7.18",
            "Details": {"GitCommit": "v1.1.13-0-g58aa920"},
        },
        {
            "Name": "docker-init",
            "Version": "0.19.0",
            "Details": {"GitCommit": "de40ad0"},
        },
    ],
    "Version": "27.0.1",
    "ApiVersion": "1.46",
    "MinAPIVersion": "1.24",
    "GitCommit": "ff1e2c0",
    "GoVersion": "go1.21.11",
    "Os": "linux",
    "Arch": "amd64",
    "KernelVersion": "5.15.133.1-microsoft-standard-WSL2",
    "BuildTime": "2024-06-24T14:57:52.000000000+00:00",
}

reference docs https://docs.docker.com/reference/dockerfile/#example-creating-inline-files

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions