Skip to content

[BUG] COPY after VOLUME should be ignored #2357

Open
@blackblather

Description

@blackblather

Contributing guidelines

I've found a bug and checked that ...

  • ... the documentation does not mention anything about my problem
  • ... there are no open or closed issues that are related to my problem

Description

According to the dockefile VOLUME documentation:

Changing the volume from within the Dockerfile: If any build steps change the data within the volume after it has been declared, those changes will be discarded.

However when we call COPY after using VOLUME the file is still copied.
Not sure where the bug is: Is the implementation wrong? Or is the documentation wrong?

Expected behaviour

COPY after VOLUME should be ignored

Actual behaviour

COPY after VOLUME is not ignored

Buildx version

github.com/docker/buildx v0.10.5 86bdced

Docker info

No response

Builders list

NAME/NODE     DRIVER/ENDPOINT STATUS  BUILDKIT                              PLATFORMS
default *     docker
  default     default         running v0.11.7-0.20230525183624-798ad6b0ce9f linux/amd64, linux/amd64/v2, linux/amd64/v3, linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/mips64le, linux/mips64, linux/arm/v7, linux/arm/v6
desktop-linux                 error

Cannot load builder desktop-linux: protocol not available

Configuration

Dockerfile:

FROM debian:bookworm-slim

RUN mkdir /content

COPY file_a.txt /content/file_a.txt

VOLUME /content

# [BUG] Should be ignored (according to the docs)
COPY file_b.txt /content/file_b.txt

Commands:

  1. docker build -t test .
  2. docker run -dt --name test-container test
  3. docker exec -it test-container

Then, from inside the container:

  1. ls content/

Notice both file_a and file_b show up. To my understanding file_b should have been ignored.

Build logs

No response

Additional info

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