Skip to content

Conversation

@KyleJamesWalker
Copy link

Add support for compose support Docker's -f/--file option from within your docker-compose.yml file.

app:
  build: .
  dockerfile: Dockerfile-alternate

I quickly threw this in, and it seems to work for me, please let me know if anything else is needed to get this into master.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't quite right, fileobj would be for the whole context. This needs to use the dockerfile kwarg.

https://github.com/docker/docker-py/blob/master/docker/client.py#L301

I don't think that option is in a release yet. I added it after the 1.0.0 release

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the version I had locally had the following, so I'm assuming it hasn't been released yet

    def build(self, path=None, tag=None, quiet=False, fileobj=None,
              nocache=False, rm=False, stream=False, timeout=None,
              custom_context=False, encoding=None, pull=True,
              forcerm=False):

This was the only way I could figure out how to get it to work (with current release), dockerfile param would be much better once it's released.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think I should update this to use dockerfile (even know it's not released yet?)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be great. I think we can ask for a new release when this is ready.

I believe fileobj doesn't actually work when the Dockerfile makes use of other files in the build context.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea I was just testing that, and you are correct. I'm fighting with getting the client installed to test it out.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use a git url with pip https://pip.pypa.io/en/latest/reference/pip_install.html#git to get the latest master of docker-py.

As a side note, I wonder if the config option should be dockerfile, to keep it consistent with the api key.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Within docker-py there's a utils.compare_version

def compare_version(v1, v2):
    """Compare docker versions

    >>> v1 = '1.9'
    >>> v2 = '1.10'
    >>> compare_version(v1, v2)
    1
    >>> compare_version(v2, v1)
    -1
    >>> compare_version(v2, v2)
    0
    """
    s1 = StrictVersion(v1)
    s2 = StrictVersion(v2)
    if s1 == s2:
        return 0
    elif s1 > s2:
        return -1
    else:
        return 1

Do you know if there's a helper like this already within compose so I could add something like :

        if 'dockerfile' in options and utils.compare_version('1.17', client.api_version()) is -1:
            raise ConfigError('Docker client API must be greater than 1.17 to support the dockerfile option')

and when building:

    def build(self, no_cache=False):
        log.info('Building %s...' % self.name)

        build_kwars = dict(
            tag=self.full_name,
            stream=True,
            rm=True,
            nocache=no_cache,
        )
        if 'dockerfile' in self.options and \
                utils.compare_version('1.17', self.client.api_version()) is not -1:
            build_kwars['dockerfile'] = self.options.get('dockerfile', None)

        build_output = self.client.build(
            self.options['build'],
            **build_kwars
        )

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't, but I wouldn't worry about it. We're planning on requiring the latest docker to pickup some new features in 1.6 anyway.

@KyleJamesWalker
Copy link
Author

I haven't tested this with unreleased docker-py, but hopefully it should work.

The dockerfile option within the docker-compose.yml file will be be checked to maintain compatibly with current docker-py

Let me know what you think, thanks for helping with this.

@KyleJamesWalker
Copy link
Author

Note: Not sure where the api version is coming from I did the following to update docker-py to master:

$ pip install -U git+git://github.com/docker/docker-py.git

Collecting git+git://github.com/docker/docker-py.git
  Cloning git://github.com/docker/docker-py.git to /var/folders/1n/0vvgtlpj6sj4tzxn5znyy4jh0000gp/T/pip-_yXZSG-build
    /usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-12.0.5-py2.7.egg/setuptools/dist.py:283: UserWarning: The version specified requires normalization, consider using '1.0.1.dev0' instead of '1.0.1-dev'.
Requirement already up-to-date: requests>=2.5.2 in /usr/local/lib/python2.7/site-packages (from docker-py==1.0.1.dev0)
Requirement already up-to-date: six>=1.3.0 in /usr/local/lib/python2.7/site-packages (from docker-py==1.0.1.dev0)
Requirement already up-to-date: websocket-client>=0.11.0 in /usr/local/lib/python2.7/site-packages (from docker-py==1.0.1.dev0)
Installing collected packages: docker-py
  Running setup.py install for docker-py
    /usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-12.0.5-py2.7.egg/setuptools/dist.py:283: UserWarning: The version specified requires normalization, consider using '1.0.1.dev0' instead of '1.0.1-dev'.
Successfully installed docker-py-1.0.1.dev0

$ docker-compose up

Docker client API must be greater than 1.17 to support the dockerfile option, currently 1.14

$ docker version

Client version: 1.5.0
Client API version: 1.17
Go version (client): go1.4.1
Git commit (client): a8a31ef
OS/Arch (client): darwin/amd64
Server version: 1.5.0
Server API version: 1.17
Go version (server): go1.4.1
Git commit (server): a8a31ef

@KyleJamesWalker
Copy link
Author

Just saw your command about the version check (got squished under the change), let me know if you'd like me to remove the checks that I added. @dnephin

@dnephin
Copy link

dnephin commented Mar 7, 2015

Ya, I would remove it. If someone is an on earlier version, they can just not specify the option and it should continue to work without the dockerfile support.

@mwean
Copy link

mwean commented Mar 8, 2015

I tried to use this locally, but ran into some issues. I got the error about the API version, so I removed those checks, but now I'm getting build() got an unexpected keyword argument 'dockerfile' I believe I have the latest docker version:

$ docker version
Client version: 1.5.0
Client API version: 1.17
Go version (client): go1.4.1
Git commit (client): a8a31ef
OS/Arch (client): darwin/amd64
Server version: 1.5.0
Server API version: 1.17
Go version (server): go1.4.1
Git commit (server): a8a31ef

And I also updated docker-py to the latest commit. Is there anything else I need to do to get this working? Thanks!

@KyleJamesWalker
Copy link
Author

@mwean You need to install the version from github pip install -U git+git://github.com/docker/docker-py.git but without some changed to docker-py the API version detects as 1.15 (but at least it won't crash when trying to pass the argument). We just have to wait for docker-py to be upgraded a bit more. Also if you install from git you'll need to edit the requirements for compose:

From:

'requests >= 2.2.1, < 2.5.0',

To:

'requests >= 2.5.2',

otherwise you'll get a version conflict.

@KyleJamesWalker
Copy link
Author

@dnephin I removed the checks, but would you like me to add the **build_kwargs portion back in. That way if they are on an outdated version of docker-py it won't crash. Or the requirements just need to be update to make sure a new enough version is required. Let me know, thanks!

@bfirsh
Copy link

bfirsh commented Mar 12, 2015

Maybe this?

app:
  build:
    context: .
    file: Dockerfile-alternate

@dnephin
Copy link

dnephin commented Mar 12, 2015

I think it's a lot less intuitive if a field can be a string or a mapping. It also makes it a lot harder (maybe impossible) to encode the expected structure of the configuration (in something like http://json-schema.org/ for example).

If we were able to break backwards compatibility, and always do

app:
  build:
    context: .

and build was never just a string, I think it would be nice.

@dnephin
Copy link

dnephin commented Mar 12, 2015

BTW, there is now a docker-py 1.1.0, so if you update the setup.py:install_requires and the requirements.txt , the tests should pass on docker 1.5+

@KyleJamesWalker
Copy link
Author

Oh awesome, I'll give it a try today!!!

@KyleJamesWalker
Copy link
Author

It's not working for me, the container builds, but then exits on up

app_1 exited with code 0

will look into this more when I have time later, unless someone has an idea, thanks.

@loic
Copy link

loic commented Mar 12, 2015

This PR has been working well for me although I had to:

  • change the version of requests in requirements.txt.
  • change the API version given to the docker-py client to 1.17.

@KyleJamesWalker
Copy link
Author

@loic you mean this line?

return Client(base_url=base_url, tls=tls_config, version='1.14', timeout=timeout)

Sorry for the close PR phone miss clicked..

Not sure what was going on, I had to remove my docker images and it seems fine now after rebuilding.

@aanand
Copy link

aanand commented Mar 13, 2015

Needs rebasing now that #1100 is merged.

@KyleJamesWalker
Copy link
Author

Rebased with upstream/master

@loic
Copy link

loic commented Mar 14, 2015

@KyleJamesWalker yes that was the line. Maybe consider squashing into a single commit?

@KyleJamesWalker
Copy link
Author

@loic Didn't know about squashing, hope that did it correctly. Thanks for the tip!

@KyleJamesWalker
Copy link
Author

Looks like all the errors are:

APIError: 404 Client Error: Not Found ("client and server don't have same version (client : 1.17, server: 1.15)")

@aanand do I need to do anything else to get this merged in?

@loic loic mentioned this pull request Mar 27, 2015
@aanand
Copy link

aanand commented Mar 27, 2015

If you rebase on master, then remove all the Docker versions apart from 1.6.0-rc2, it should fix the build.

@KyleJamesWalker
Copy link
Author

@aanand Rebased.

Also amended commit to include a properly formatted DCO marker.

@aanand
Copy link

aanand commented Mar 27, 2015

Dockerfile still needs updating to remove Docker versions 1.3.3, 1.4.1 and 1.5.0.

@throrin19
Copy link

+1 I can't wait for this

@jonbrouse
Copy link

+1 this is gonna be awesome

@jakubriedl
Copy link

+1 cool feature - we are waiting for it

@aanand aanand added this to the 1.3.0 milestone Apr 21, 2015
@aanand
Copy link

aanand commented Apr 24, 2015

requests 2.6.1 is out, so try updating requirements.txt with requests==2.6.1.

@KyleJamesWalker
Copy link
Author

Thanks, I'll give it a try when I make it into work today!

Signed-off-by: Kyle James Walker <KyleJamesWalker@gmail.com>
@KyleJamesWalker
Copy link
Author

WOOOO!!!!!!!!!!!

@joost
Copy link

joost commented Apr 24, 2015

👍

@aanand
Copy link

aanand commented Apr 27, 2015

LGTM

@dnephin
Copy link

dnephin commented Apr 27, 2015

LGTM!

dnephin added a commit that referenced this pull request Apr 27, 2015
Support alternate Dockerfile name.
@dnephin dnephin merged commit a89bc30 into docker:master Apr 27, 2015
@aanand
Copy link

aanand commented Apr 27, 2015

giphy

@jonbrouse
Copy link

Thank you!
Celebrate

OMG THANKYOU

@wokim
Copy link

wokim commented May 13, 2015

👍

@stevenjack
Copy link

Great to see this finally in!

party

@zkilgore
Copy link

👍👍👍👍👍👍👍👍👍👍👍

@jasonferrier
Copy link

How about adding it to the docker-compose.yml documentation? It took me a while to think of searching the Issues and PR's on here to figure out that it is possible...

Nevermind, after digging more I see that this will be part of Docker Compose v1.3.0 which is slated to be released on June 26, 2015.

@KyleJamesWalker
Copy link
Author

Oh you beat me to it, can't wait for it in the main release! :P

@joost
Copy link

joost commented Jun 11, 2015

Docker Compose v1.3.0rc2 Homebrew Formula: https://gist.github.com/joost/20934650f68dd561fc35

@aanand
Copy link

aanand commented Jun 12, 2015

Please note that Homebrew isn't an official installation method! Head here to install from binaries or pip: https://github.com/docker/compose/releases/tag/1.3.0rc2

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 this pull request may close these issues.