Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"COPY . ." command in Dockerfile does not copy all contents when using Kaniko. #2684

Open
iuriemuradu opened this issue Aug 16, 2023 · 4 comments
Labels
area/documentation For all bugs related to documentation differs-from-docker kind/bug Something isn't working kind/question Further information is requested priority/p2 High impact feature/bug. Will get a lot of users happy

Comments

@iuriemuradu
Copy link

iuriemuradu commented Aug 16, 2023

Actual behavior
When utilizing the "COPY . ." command in my Dockerfile, Kaniko does not seem to copy all the contents of the repository into the container.

Expected behavior
All contents of the repository should be copied into the container when using the "COPY . ." command.

To Reproduce
Steps to reproduce the behavior:

  1. Use a Dockerfile with the command "COPY . ."
  2. Build the image using Kaniko

Dockerfile

FROM python:3.8-slim as builder
RUN mkdir src
RUN mkdir src/results
COPY src/ /src
WORKDIR /src
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
RUN apt-get update && \
    apt-get install -y --no-install-recommends build-essential vim curl

COPY . . <<-- HERE

RUN pip wheel --no-cache-dir --no-deps --wheel-dir /src/wheels -r requirements.txt
# final stage
FROM python:3.8-slim as proc_stage
ENV PYTHONPATH "${PYTHONPATH}:/"
ENV CONF_SRC_DIR /mnt
ENV CONF_DST_DIR /src
COPY --from=builder /src/wheels /wheels
COPY --from=builder /src/requirements.txt .
ADD files/run.sh /run.sh
RUN pip install --no-cache /wheels/*

COPY . . <<-- HERE

RUN ls -la
WORKDIR /
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
ENTRYPOINT [ "bash","run.sh" ]

Kaniko Image
gcr.io/kaniko-project/executor:v1.14.0

@aaron-prindle
Copy link
Collaborator

aaron-prindle commented Aug 16, 2023

Thank you for flagging this issue @iuriemuradu. Kaniko by default has a set of "denylist" root fs paths that kaniko ignores when snapshotting the filesystem. This flag is an example of this:
https://github.com/GoogleContainerTools/kaniko#flag---ignore-var-run

The flag explains that by default, kaniko ignores changes in /var/run when doing snapshot operations (changes made via COPY, ADD, etc.)

Currently users can tweak the denylist using the flag options available. This might be a potential workaround assuming the missing files are in one of the dirs the flags support (namely /var/run):
https://github.com/GoogleContainerTools/kaniko#flag---ignore-var-run
https://github.com/GoogleContainerTools/kaniko#flag---ignore-path

Related code for this denylist is here:
https://github.com/GoogleContainerTools/kaniko/blob/main/pkg/util/fs_util.go#L61-L78
https://github.com/GoogleContainerTools/kaniko/blob/main/pkg/util/fs_util.go#L1032-L1046
https://github.com/GoogleContainerTools/kaniko/blob/main/pkg/util/fs_util.go#L449-L490

and is described as:

// InitIgnoreList will initialize the ignore list using:
// - defaultIgnoreList
// - mounted paths via DetectFilesystemIgnoreList()

Running kaniko in a docker container via:

    docker run \
        -v "$HOME"/.config/gcloud:/root/.config/gcloud \
        -v "$context":/workspace \
        gcr.io/kaniko-project/executor:latest \
        --dockerfile "${dockerfile}" --destination "${destination}" --context dir:///workspace/ \
        --cache="${cache}"

The denylist looks something like the below:
/kaniko
/etc/mtab
/tmp/apt-key-gpghome
/var/run
/proc
/dev
/dev/pts
/sys
/sys/fs/cgroup
/dev/mqueue
/dev/shm
/workspace
/etc/resolv.conf
/etc/hostname
/etc/hosts
/root/.config/gcloud
/proc/bus
/proc/fs
/proc/irq
/proc/sys
/proc/sysrq-trigger
/proc/acpi
/proc/kcore
/proc/keys
/proc/timer_list
/sys/firmware

@aaron-prindle
Copy link
Collaborator

aaron-prindle commented Aug 16, 2023

From the issue here I believe the actionable pieces here include:

  • better documenting kaniko's denylist and cite this is a point of possible friction in documentation
  • leave this issue open to track potential fixes here

@aaron-prindle aaron-prindle added kind/question Further information is requested kind/bug Something isn't working area/documentation For all bugs related to documentation priority/p2 High impact feature/bug. Will get a lot of users happy works-with-docker differs-from-docker and removed works-with-docker labels Aug 17, 2023
@iuriemuradu
Copy link
Author

Thank you so much @aaron-prindle for your answer,
Nevertheless I am still not sure how this can help me use COPY . . as intended, or maybe at this phase of development it is not even possible.
I would appreciate if you could bring more light on that particular issue that I have posted.
Thank you so much for your effort.

@iuriemuradu
Copy link
Author

Actually I tried --ignore-path include path that I need to be copied and still the files are not preserved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/documentation For all bugs related to documentation differs-from-docker kind/bug Something isn't working kind/question Further information is requested priority/p2 High impact feature/bug. Will get a lot of users happy
Projects
None yet
Development

No branches or pull requests

2 participants