docker icon indicating copy to clipboard operation
docker copied to clipboard

docker_image does not support running from a directory

Open palfrey opened this issue 8 years ago • 4 comments

Dockerfile ADD commands are often relative to a directory, but the docker_image command doesn't support any sort of "run from this directory" command. You can work around this by choosing a directory instead and this works for most situations, but it would be a useful addition.

palfrey avatar Feb 02 '17 15:02 palfrey

Sure it does.

https://github.com/chef-cookbooks/docker/blob/master/test/cookbooks/docker_test/recipes/image.rb#L129-L148

someara avatar Feb 02 '17 19:02 someara

Sorry, I should clarify. It supports "run from this directory" if the file you want to build from is called "Dockerfile". It doesn't support the use case I had, which was "run from this directory, but use this differently named file as the Dockerfile" (because I actually had two different Dockerfile's I wanted to run that were both in that directory). I solved this in my case by splitting everything up into separate folders and renaming the files to Dockerfile, but that won't fix everyone's situations.

palfrey avatar Feb 05 '17 20:02 palfrey

I'm trying to figure out what support for this would look like....

First thing would be the interface... I image we'd need a property on docker_image and an example of it being exercised somewhere near here:

https://github.com/chef-cookbooks/docker/blob/master/test/cookbooks/docker_test/recipes/image.rb#L103-L105

Then somehow tweak this function: https://github.com/chef-cookbooks/docker/blob/master/libraries/helpers_image.rb#L9

It really boils down to if the underlying docker-api rubygem supports doing this.

-s

someara avatar Feb 15 '17 15:02 someara

The underlying API definitely supports it. One of the examples from docker-api is Docker::Image.build_from_dir('.', { 'dockerfile' => 'Dockerfile.Centos' }) i.e. specifying directory and Dockerfile name

palfrey avatar Feb 18 '17 17:02 palfrey