Configs

Create a config

import asyncio
import aiodocker

docker = aiodocker.Docker()

async def create_config():
    config = await docker.configs.create(
        name="my_config",
        data="This is my config data"
    )
    await docker.close()
    return config

async def create_service(TaskTemplate):
    service = await docker.services.create(
        task_template=TaskTemplate,
        name="my_service"
    )
    await docker.close()

if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    my_config = loop.run_until_complete(create_config())
    TaskTemplate = {
        "ContainerSpec": {
            "Image": "redis",
            "Configs": [
            {
                "File": {
                    "Name": my_config["Spec"]["Name"],
                    "UID": "0",
                    "GID": "0",
                    "Mode": 292
                },
                "ConfigID": my_config["ID"],
                "ConfigName": my_config["Spec"]["Name"],
            }
            ],
        },
    }
    loop.run_until_complete(create_service(TaskTemplate))
    loop.close()

Reference

DockerConfigs

class aiodocker.configs.DockerConfigs(docker)[source]
coroutine create(self, name, data, *, b64=False, labels=None, templating=None)[source]

Create a config

Parameters
  • name (str) – name of the config

  • labels (Optional[List]) – user-defined key/value metadata

  • data (str) – config data

  • b64 (bool) – True if data is already Base64-url-safe-encoded

  • templating (Optional[Mapping]) – Driver represents a driver (network, logging, secrets).

Return type

Mapping[str, Any]

Returns

a dict with info of the created config

coroutine delete(self, config_id)[source]

Remove a config

Parameters

config_id (str) – ID or name of the config

Return type

bool

Returns

True if successful

coroutine inspect(self, config_id)[source]

Inspect a config

Parameters

config_id (str) – ID of the config

Return type

Mapping[str, Any]

Returns

a dict with info about a config

coroutine list(self, *, filters=None)[source]

Return a list of configs

Parameters

filters (Optional[Mapping]) – a dict with a list of filters

Available filters:

id=<config id> label=<key> or label=<key>=value name=<config name> names=<config name>

Return type

List[Mapping]

coroutine update(self, config_id, version, *, name=None, data=None, b64=False, labels=None, templating=None)[source]

Update a config.

Parameters
  • config_id (str) – ID of the config.

  • name (Optional[str]) – name of the config

  • labels (Optional[List]) – user-defined key/value metadata

  • data (Optional[str]) – config data

  • b64 (bool) – True if data is already Base64-url-safe-encoded

  • templating (Optional[Mapping]) – Driver represents a driver (network, logging, secrets).

Return type

bool

Returns

True if successful.