Skip to content

Possible undocumented COPY case #19500

@ghost

Description

Is this a docs issue?

  • My issue is about the documentation content or website

Type of issue

Information is incorrect

Description

The documentation for COPY states:

  • The path must be inside the build context; you can't use COPY ../something /something, because the builder can only access files from the context, and ../something specifies a parent file or directory of the build context root.

Let's say my Dockerfile is not in the project root directory but nested inside some directory, e.g.:

bin/
    file.go
docker/
    Dockerfile

Now I run docker build -f docker/Dockerfile -t my-tag . from the project root so the . means the build context root is the project root.
The following Dockerfile works:

FROM alpine

COPY bin/file.go /bin/file.go

However this Dockerfile also works (notice ../ in the path for file.go):

FROM alpine

COPY ../bin/file.go /bin/file.go

I would expect this to fail as the build context is a project root and using ../ we go to the parent directory which is outside of the build context.

Location

https://docs.docker.com/reference/dockerfile/

Suggestion

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions