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

Implement docker contexts #2495

Merged

Conversation

aiordache
Copy link
Collaborator

Implement a simple docker-compatible context management.

Usage examples:

  • Get context
import json
from docker.context import ContextAPI

ctx = ContextAPI.get_context()
print(json.dumps(ctx.Metadata, indent = 2))

Output

{
  "Name": "default",
  "Metadata": {
    "StackOrchestrator": "swarm"
  },
  "Endpoints": {
    "docker": {
      "Host": "unix:///var/run/docker.sock",
      "SkipTLSVerify": false
    }
  }
}
  • Create context
ctx = ContextAPI.create_context(name='test')
print(ctx.Name)

Output

test
  • Inspect context
inspect = ContextAPI.inspect_context('test')
print(json.dumps(inspect, indent = 2))

Output

{
  "Name": "test",
  "Metadata": {
    "StackOrchestrator": "swarm"
  },
  "Endpoints": {
    "docker": {
      "Host": "unix:///var/run/docker.sock",
      "SkipTLSVerify": false
    }
  },
  "TLSMaterial": {},
  "Storage": {
    "MetadataPath": "~/.docker/contexts/meta/9f86d081884c7d659a2f2cd15d6c15b0f00a08",
    "TLSPath": "~/.docker/contexts/tls/9f86d081884c7d659a2f2cd15d6c15b0f00a08/"
  }
}
  • List contexts
for ctx in ContextAPI.contexts():
    print(ctx.Name)

Output

default
test

Signed-off-by: Anca Iordache anca.iordache@docker.com

@aiordache aiordache force-pushed the issue#28_compose_context_target branch 6 times, most recently from 9fad9c0 to d92ab26 Compare January 21, 2020 10:35
docker/context/api.py Outdated Show resolved Hide resolved
@aiordache aiordache force-pushed the issue#28_compose_context_target branch 4 times, most recently from 8f99eb5 to ec9fee4 Compare January 22, 2020 15:31
docker/constants.py Outdated Show resolved Hide resolved
docker/context/api.py Outdated Show resolved Hide resolved
docker/context/api.py Outdated Show resolved Hide resolved
docker/context/api.py Outdated Show resolved Hide resolved
docker/context/api.py Outdated Show resolved Hide resolved
.vscode/settings.json Outdated Show resolved Hide resolved
docker/context/api.py Outdated Show resolved Hide resolved
docker/context/api.py Outdated Show resolved Hide resolved
@aiordache aiordache force-pushed the issue#28_compose_context_target branch from 2a450e3 to 6ce8d73 Compare February 4, 2020 19:30
docker/context/config.py Outdated Show resolved Hide resolved
docker/context/config.py Outdated Show resolved Hide resolved
docker/context/config.py Outdated Show resolved Hide resolved
Signed-off-by: Anca Iordache <anca.iordache@docker.com>
@aiordache aiordache force-pushed the issue#28_compose_context_target branch from 6cc86ea to 64fdb32 Compare February 5, 2020 13:50
@ulyssessouza ulyssessouza merged commit c6a33f2 into docker:master Feb 5, 2020
@ulyssessouza ulyssessouza added this to the 4.2.0 milestone Feb 6, 2020
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.

None yet

4 participants