Docker Service#
Docker Service Class#
Classes:
|
Deploy docker agents on the nodes and registry cache(optional) |
- class enoslib.service.docker.docker.Docker(*, agent: List[Host] | None = None, docker_version: str | None = None, registry: List[Host] | None = None, registry_opts: Dict | None = None, bind_var_docker: str | None = None, swarm: bool = False, credentials: Dict | None = None, nvidia_toolkit: bool | None = None)#
Deploy docker agents on the nodes and registry cache(optional)
This assumes a debian/ubuntu base environment and aims at producing a quick way to deploy docker and optionally a registry on your nodes.
If an NVidia GPU is detected on a node, the nvidia-container-toolkit will be also installed automatically. See https://docs.nvidia.com/datacenter/cloud-native/ Installation of the nvidia-container-toolkit can be forced with nvidia_toolkit=True, or prevented with nvidia_toolkit=False.
Examples
# Simply install latest docker agent without any registry docker = Docker(agent=roles["agent"]) # Install a specific version of docker agent (recommended) docker = Docker(agent=roles["agent"], docker_version="25.0") # Don't install nvidia-container-toolkit even if a nvidia GPU # is detected on the target hosts. docker = Docker(agent=roles["agent"], nvidia_toolkit=False) # Install and use an internal registry on the specified host docker = Docker(agent=roles["agent"], registry=roles["registry"]) # Install and use an internal registry on the first agent docker = Docker(agent=roles["agent"], registry_opts=dict(type="internal")) # Use an external registry docker = Docker(agent=roles["compute"] + roles["control"], registry_opts = {"type": "external", "ip": "192.168.42.1", "port": 4000})
1import logging 2 3import enoslib as en 4 5en.init_logging(level=logging.INFO) 6en.check() 7 8conf = ( 9 en.VagrantConf() 10 .add_machine(roles=["control"], flavour="tiny", number=1) 11 .add_machine(roles=["compute"], flavour="tiny", number=1) 12 .add_network(roles=["mynetwork"], cidr="192.168.42.0/24") 13 .finalize() 14) 15 16# claim the resources 17provider = en.Vagrant(conf) 18roles, networks = provider.init() 19 20# generate an inventory compatible with ansible 21roles = en.sync_info(roles, networks) 22 23docker = en.Docker(registry=roles["control"], agent=roles["compute"]) 24docker.deploy() 25docker.backup() 26docker.destroy() 27 28# destroy the boxes 29provider.destroy()
1import logging 2from pathlib import Path 3 4import enoslib as en 5 6en.init_logging(level=logging.INFO) 7en.check() 8 9job_name = Path(__file__).name 10 11CLUSTER = "paravance" 12 13conf = en.G5kConf.from_settings( 14 job_type=[], job_name=job_name, walltime="0:30:00" 15).add_machine(roles=["control"], cluster=CLUSTER, nodes=2) 16 17provider = en.G5k(conf) 18roles, networks = provider.init() 19 20 21registry_opts = dict(type="external", ip="docker-cache.grid5000.fr", port=80) 22 23d = en.Docker( 24 agent=roles["control"], 25 docker_version="25.0", 26 bind_var_docker="/tmp/docker", 27 registry_opts=registry_opts, 28 # Optional credentials for docker hub 29 # credentials=dict(login="mylogin", password="mytoken"), 30) 31d.deploy() 32 33 34# Release all Grid'5000 resources 35provider.destroy()
- Parameters:
agent (list) – list of
enoslib.Host
where the docker agent will be installeddocker_version (str) – major version of Docker to install. Defaults to latest.
registry (list) – list of
enoslib.Host
where the docker registry will be installed.registry_opts (dict) – registry options. The dictionary must comply with the schema.
bind_var_docker (str) – If set the default docker state directory (/var/lib/docker/) will be bind mounted in this directory. The rationale is that on Grid’5000, there isn’t much disk space on /var/lib by default. Set it to False to disable the fallback to the default location.
swarm (bool) – Whether a docker swarm needs to be created over the agents. The first agent will be taken as the swarm master.
credentials (dict) – Optional ‘login’ and ‘password’ for Docker hub. Useful to access private images, or to bypass Docker hub rate-limiting: in that case, it is recommended to use a token with the “Public Repo Read-Only” permission as password, because it is stored in cleartext on the nodes.
nvidia_toolkit (bool) – Whether to install nvidia-container-toolkit. If set to None (the default), Enoslib will try to auto-detect the presence of a nvidia GPU and only install nvidia-container-toolkit if it finds such a GPU. Set to True to force nvidia-container-toolkit installation in all cases, or set to False to prevent nvidia-container-toolkit installation in all cases.
- backup()#
(Not implemented) Backup docker.
Feel free to share your ideas.
- deploy()#
Deploy docker and optionally a docker registry cache.
- destroy()#
(Not implemented) Destroy docker
Feel free to share your ideas.