Skip to content

Sensible url handling - #140

Merged
mpetazzoni merged 2 commits into
docker:masterfrom
aanand:sensible-url-handling
Jan 14, 2014
Merged

mpetazzoni merged 2 commits into
docker:masterfrom
aanand:sensible-url-handling

Conversation

@aanand

@aanand aanand commented Jan 14, 2014

Copy link
Copy Markdown
Contributor

Now that the Docker client supports setting the daemon URL via the DOCKER_HOST environment variable, it'd be nice to be able to get the same behaviour from docker-py. I'm a bit wary of libraries that configure themselves using magic globals, so I haven't baked in direct reading of os.environ, but next best thing:

import os
from docker import Client
client = Client(os.environ.get('DOCKER_HOST'))

I think that's a good application of "explicit is better than implicit".

The actual changes I've made:

  • tcp:// urls are converted to http://
  • None is converted to unix://var/run/docker.sock

This means docker-py will do the Right Thing if the base url is set
using the new `DOCKER_HOST` environment variable, for example.
(http://docs.docker.io/en/latest/commandline/cli/)
This makes it very simple to get identical behaviour to the CLI:

    client = Client(os.environ.get('DOCKER_HOST'))
@ghost ghost assigned mpetazzoni Jan 14, 2014
mpetazzoni added a commit that referenced this pull request Jan 14, 2014
@mpetazzoni
mpetazzoni merged commit d73901a into docker:master Jan 14, 2014
@mpetazzoni

Copy link
Copy Markdown
Contributor

LGTM. Thanks!

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.

2 participants