aio-libs / aiodocker

Python Docker API client based on asyncio and aiohttp
Other
427 stars 97 forks source link

Documentation and type hints for config schema #829

Closed EdAyers closed 1 year ago

EdAyers commented 1 year ago

Hi all, it's difficult to use this library without knowing the schema that the config dictionary argument is supposed to take (eg to client.containers.create()). For example, does "Volumes" : .. take a list or a dictionary? What are the valid fields?

The dream would be to have the config argument be a TypedDict or some other structured type so that we get type hints in the IDE.

I've looked for official docker documentation on the schema but I can't find it. The best I've found is this guide which doesn't give an explicit schema. Another option is to attempt to recover the schema from calling docker inspect on different objects. If you know where the documentation for the schema is please let me know.

naufalafif commented 1 year ago

Hi @EdAyers , this library is wrapper for docker engine API. so all params are refering to docker API itself.

you can find it on its API documentation. https://docs.docker.com/engine/api/v1.43/#tag/Container/operation/ContainerCreate

How to use it. 1) you can use all params on number 2 (image below) as config.

config = {
     "Cmd": ["/bin/ls"],
     "Image": "alpine:latest",
     "AttachStdin": False,
     "AttachStdout": False,
     "AttachStderr": False,
     "Tty": False,
     "OpenStdin": False,
 }

2) you can use params on number 1 (image below) as param for containers.create function

containers.create(name="desired_name", config=config)

Screenshot 2023-07-19 200916

naufalafif commented 1 year ago

library official documentation: https://aiodocker.readthedocs.io/en/latest/containers.html it doesn't provide all available config, so you'll have to check docker API docs also to be able to use it.

EdAyers commented 1 year ago

Thanks so much, I was struggling to find the API docs.

naufalafif commented 1 year ago

Hi @EdAyers , glad to hear that. i think you can close this issue