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

build_from_dir can't find Dockerfile when .dockerignore is "*" #484

Open
caleb opened this issue May 22, 2017 · 5 comments · May be fixed by #541
Open

build_from_dir can't find Dockerfile when .dockerignore is "*" #484

caleb opened this issue May 22, 2017 · 5 comments · May be fixed by #541

Comments

@caleb
Copy link

caleb commented May 22, 2017

This is a strange case maybe, but it's something that works on the command line so I thought it might be considered a bug.

I have a .dockerignore file in my project that is just * to ignore all files (to speed up building the image by not copying everything in the project to docker), and when I try to build my container, I get the error:

Generated at 2017-05-22 10:26:53 -0400
Docker::Error::ServerError: docker_image[bdcreporter-wordpress] (bdcreporter::docker_images line 18) had an error: Docker::Error::ServerError: Cannot locate specified Dockerfile: Dockerfile

/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/docker-api-1.33.2/lib/docker/connection.rb:50:in `rescue in request'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/docker-api-1.33.2/lib/docker/connection.rb:38:in `request'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/docker-api-1.33.2/lib/docker/connection.rb:65:in `block (2 levels) in <class:Connection>'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/docker-api-1.33.2/lib/docker/image.rb:259:in `build_from_tar'
/opt/chef/embedded/lib/ruby/gems/2.3.0/gems/docker-api-1.33.2/lib/docker/image.rb:278:in `build_from_dir'

The problem is, docker-api is reading the .dockerignore file when building the tar to send to docker and is building the tar without even the Dockerfile.

I've tried adding the newly supported negation syntax to my Dockerfile:

*
!Dockerfile

but this doesn't work either, I still get the error.

Maybe Dockerfile should be a special case and always be included?

Thanks! I use this library via the Docker chef cookbook every day.

EDIT: I can workaround this problem by just building from the Dockerfile rather than building from the directory.

-Caleb

@ghost
Copy link

ghost commented Oct 26, 2017

Any possibility this can be addressed?

@marcelocarlos
Copy link

marcelocarlos commented Feb 6, 2018

Hi guys, is the fix in 1320659 going to be merged?

@onnimonni
Copy link

onnimonni commented Dec 1, 2018

This also happens if .dockerignore contains Dockerfile.

$ ls ./test
.dockerignore
Dockerfile
$ cat Dockerfile
FROM alpine
$ cat ./test/.dockerignore
Dockerfile
$ irb
> require 'docker-api'
> Docker::Image.build_from_dir("test", {t: "test"})
...
Docker::Error::ServerError (Cannot locate specified Dockerfile: Dockerfile)

But for example the same example works perfectly with docker-compose.

@tlunter
Copy link
Contributor

tlunter commented Dec 4, 2018

So far that I know, @ghostsquad didn't open a PR against this repo with that fix. Would be willing to take a look if that happens.

@ghostsquad ghostsquad linked a pull request Dec 4, 2018 that will close this issue
@ghostsquad
Copy link

@tlunter PR submitted. Apparently I wrote the code over a year ago, and forgot to submit a PR. IIRC, I wasn't super confident in my changes, which is why I waited on the PR. I'd love some more eyes on the logic.

kiela pushed a commit to AcornsGrowAU/docker-api that referenced this issue May 28, 2019
Always exclude Dockerfile and .dockerignore from being ignored.

https://docs.docker.com/engine/reference/builder/#dockerignore-file
> You can even use the .dockerignore file to exclude the Dockerfile and .dockerignore files.
> These files are still sent to the daemon because it needs them to do its job.
> But the ADD and COPY instructions do not copy them to the image.

resolves upserve#484
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants