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

The .dockerignore file also matches between stages #595

Closed
michas2 opened this issue Mar 4, 2019 · 14 comments · Fixed by #1234
Closed

The .dockerignore file also matches between stages #595

michas2 opened this issue Mar 4, 2019 · 14 comments · Fixed by #1234
Assignees
Labels
area/dockerfile-command For all bugs related to dockerfile file commands in progress priority/p1 Basic need feature compatibility with docker build. we should be working on this next.

Comments

@michas2
Copy link

michas2 commented Mar 4, 2019

Actual behavior
The patterns in .dockerignore match not only in workdir but also when copying between stages.

Expected behavior
I expected kaniko to have the same semantics as in docker build.
The patterns should match only on initial import relative to /workdir/ not between stages relative to /.

To Reproduce

$ cat Dockerfile 
from busybox
run mkdir /foo/
run touch /foo/bar
run ls -l / /foo/

from busybox
copy --from=0 /foo/ /foo/
run ls -l / /foo/
$ cat .dockerignore 
/foo/
$ docker run --rm -v $PWD:/workspace gcr.io/kaniko-project/executor:v0.9.0 --no-push
[...]
INFO[0007] copy --from=0 /foo/ /foo/                    
INFO[0007] Taking snapshot of full filesystem...        
INFO[0007] Skipping paths under /kaniko, as it is a whitelisted directory 
INFO[0007] Skipping paths under /dev, as it is a whitelisted directory 
INFO[0007] Skipping paths under /proc, as it is a whitelisted directory 
INFO[0007] Skipping paths under /sys, as it is a whitelisted directory 
INFO[0007] Skipping paths under /workspace, as it is a whitelisted directory 
INFO[0008] No files were changed, appending empty layer to config. No layer added to image. 
INFO[0008] run ls -l / /foo/                            
INFO[0008] cmd: /bin/sh                                 
INFO[0008] args: [-c ls -l / /foo/]                     
ls: /foo/: No such file or directory

Trying the same with v0.7.0 or docker build works fine.

@MajorBreakfast
Copy link

MajorBreakfast commented Apr 2, 2019

I ran into the same issue. Here's my minimal test scenario

Dockerfile:

FROM alpine:3.9 AS intermediate

RUN cd /
RUN mkdir myDir
RUN echo "I am here!!!" > /myDir/shouldBeCopied.txt

FROM alpine:3.9

COPY --from=intermediate /myDir/shouldBeCopied.txt wasCopied.txt

RUN cat wasCopied.txt

Dockerignore:

# Each one prevents shouldBeCopied.txt from being copied (remove all these to make it work)
/myDir/shouldBeCopied.txt
/myDir
myDir

# Weirdly not a problem
shouldBeCopied.txt
docker run -v ${PWD}:/project gcr.io/kaniko-project/executor:debug-c8fabdf6e43b19f6a223f1d0b06e127d0774bd7e executor --context project --dockerfile ./project/Dockerfile --no-push

Expected output: Log message "I am here!!!" contained in the build log
Actual output:

INFO[0017] COPY --from=intermediate /myDir/shouldBeCopied.txt wasCopied.txt 
error building image: error building stage: copy failed: no source files specified

@heroic
Copy link

heroic commented Apr 23, 2019

We got this issue today as well. node_modules from the first step would not get copied to the next as long as it was present in .dockerignore

@davidcurrie
Copy link

Hitting this too. Particularly problematic if, like me, your .dockerignore typically starts with a ** followed by a whitelist.

@leosunmo
Copy link
Contributor

Hit the same issue as @heroic with node_modules not being copied between build steps.
As far as I can tell this seems like the common pattern for front-end builds that utilise multiple build steps (which is more and more common as you don't want all that initial build bloat in the final image) and the node_modules directory seems a common target to ignore. Unsure what the best workaround is for now but we've decided to remove .dockerignore completely and try to rely on Kaniko as much as possible.

@thewilli
Copy link

@leosunmo Unsure what the best workaround is for now but we've decided to remove .dockerignore completely and try to rely on Kaniko as much as possible.

For sure not the best workaround, but I went with using the executor:debug image to have a shell and then alter / remove the .dockerignore without any persistent changes to the repository in the corresponding CI step only.

@i-wilson
Copy link

I ended up getting around this the same way @thewilli

I'd love to actually help fix this, Is the logic simple between how docker cli handles this vs kaniko? I'll dig around but if someone could point me in the right direction I'd appreciate it.

@donmccasland donmccasland added area/dockerfile-command For all bugs related to dockerfile file commands priority/p1 Basic need feature compatibility with docker build. we should be working on this next. labels Sep 20, 2019
mithrandi added a commit to mithrandi/isaacranks that referenced this issue Dec 28, 2019
@tejal29 tejal29 added this to the GA Release v1.0.0 milestone Jan 10, 2020
@tejal29 tejal29 self-assigned this Jan 23, 2020
@tejal29
Copy link
Contributor

tejal29 commented Feb 4, 2020

thanks all. i have a fix for this and will try to get this in by next release.

@niklasnatter
Copy link

that are great news - thanks a lot! @tejal29

@afirth
Copy link

afirth commented Mar 9, 2020

@tejal29 is this fixed now? I noticed that .dockerignore doesn't seem to work at all in 0.16.0, but it's back in 0.18.0 - couldn't find anything in the release notes though

@tejal29
Copy link
Contributor

tejal29 commented Mar 11, 2020

@afirth no i have not merged the patch. i will get it in v0.19.0

@glen-84
Copy link

glen-84 commented Mar 18, 2020

@tejal29 Did you forget about this? 😞

@mashail
Copy link

mashail commented Mar 30, 2020

The issue is still exist in version 0.19.0!!

@eonicle
Copy link

eonicle commented Apr 16, 2020

Just hit that issue for a first time - pretty frustrating. If real fix is delayed, this should at least be mentioned somewhere in docs.

@tejal29
Copy link
Contributor

tejal29 commented May 6, 2020

Sorry folks, this got dropped. Fix here -> #1234

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/dockerfile-command For all bugs related to dockerfile file commands in progress priority/p1 Basic need feature compatibility with docker build. we should be working on this next.
Projects
None yet