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

Docker Context for remote host management #647

Open
shantanoo-desai opened this issue Jun 15, 2023 · 4 comments
Open

Docker Context for remote host management #647

shantanoo-desai opened this issue Jun 15, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@shantanoo-desai
Copy link

shantanoo-desai commented Jun 15, 2023

SUMMARY

Since Docker v18.09+ it is possible to use the same docker CLI on a Controller Node to get access to remote Managed Nodes. This is generally achieved initially by using docker context create ....

This command is capable enough to work with Docker Swarm, Kubernetes for Orchestration as well for standalone remote nodes over TCP (with / without TLS), as well as SSH.

Thorough Documentation can be found on Docker Docs: Docker Context.

The tool also provides facilities or exporting / importing these created contexts as well as controlling the Docker Containers on Remote nodes.

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

community.docker.docker_context

ADDITIONAL INFORMATION

This may be an example module called docker_context:

- name: Create Docker Context for Hosts in Inventory
  community.docker.docker_context:
    name: "ctx-{{ inventory_hostname }}"
    description: "docker context for remote node: {{ inventory_hostname }}"
    state: created
    endpoint: "ssh://{{ inventory_hostname }}"

There are certainly benefits where at least from the CLI, the following examples can perform tasks, which are performed locally, also on a remote machine

# list running docker containers on `my-host-1`

docker --context=ctx-my-host-1 ps -a

In conjuction with docker compose one can deploy a compose application without needing to copy a compose file to the remote machine

# executing in the same directory as `docker-compose.yml`
docker --context=ctx-my-host-1 compose up -d

A well written Docker Post for deploying on Remote Docker Host with docker compose

@felixfontein felixfontein added the enhancement New feature or request label Jun 16, 2023
@felixfontein
Copy link
Collaborator

At least docker context ls and docker context inspect have a --format json parameter :)

@shantanoo-desai
Copy link
Author

@shantanoo-desai
Copy link
Author

shantanoo-desai commented Jun 16, 2023

Initial trials with docker-py:

import docker

client = docker.DockerClient(base_url="ssh://<user>@<hostname>", use_ssh_client=True)
client.containers.list() # will show containers on the remote machine

This however requires paramiko to be installed as a pip package to make the use_ssh_client parameter work. I haven't got around with how to use the Context and ContextAPI

@Vladimir-csp
Copy link

Would be great if all modules that interact with docker also supported contexts, including default one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants