Migrate from dockerpy to aiodocker
Description
Dockerpy is not asyncio friendly, a bit of a hassle to use and no longer actively maintained as the Docker team does not use python for docker compose anymore.
Aiodocker is asyncio friendly, still a bit of a hassle to use but is actively maintained by a new group.
We should migrate to the latter and begin contributing to it in order to improve the experience. Because we need a good docker client library in Supervisor, its a big part of what we do.
Additional context
No response
Hi @mdegat01, thank you for your contribution!
Task issues are restricted to Open Home Foundation staff and authorized contributors.
If you would like to:
- Report a bug: Please use the bug report form
- Request a feature: Please submit to Feature Requests
If you believe you should have access to create Task issues, please contact the maintainers.
Going to start to collect a running list of things I've found as I go through API by API.
Differences of note:
-
images.getis equivalentimages.inspectin aiodocker. In Dockerpy we received anImageobject with the inspect details inattrsand some other common fields mapped into properties (id,tags, etc.) -
images.listin aiodocker pushes all kwargs directly to theGET images/jsonAPI. This makes it far less friendly to use then Dockerpy'simages.listthat accepted a few common params likenameand handled making the query string json for you. This code is a reference for how that works. -
images.deletein aiodocker =images.removein dockerpy - containers are very different from images.
containers.getandcontainers.listreturn aDockerContainerinstance. Unlike with dockerpy this instance does not have the inspect data, its only field isid. You must useDockerContainer.showto get the inspect info which is a coroutine and makes another API call to docker. - aiodocker has even less definition for exceptions then dockerpy. For instance to determine if an image or container is "Not Found" you catch the generic
aiodocker.exceptions.DockerErrorand check iferr.status == 404. Compare to dockerpy which raisesdocker.errors.NotFound - To tag an image, you use
images.tagand just pass the image id as the first parameter. Whereas dockerpy did that for you sinceImageinstances had atagmethod. It's otherwise identical - aiodocker's
images.import_imagefunctions identically to dockerpy'simages.loadin terms of inputs, it wants a binary stream of the tarball although aiodocker has a stream function to presumably tell us about images as they load. They differ massively in output. Dockerpy nicely parses the log of the output to give usImageobjects as shown here. We need this so we'll have to recreate for aiodocker, it simply gives us that log.
Running list of PRs we will need for aiodocker:
- There is no equivalent to
docker infoin aiodocker. They only have an equivalent todocker versionand we need more info then that provides - ~~
images.pulldoes not support providing aplatformin aiodocker. We cannot use it right now~~ Actually its in there. Somehow I missed it 🙈
There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.
Check default timeout to be in similar ball-park to dockerpy (specifically when adding events).
Maybe also add timeout parameter to the import_image command. See also https://github.com/home-assistant/supervisor/pull/6391#issuecomment-3608791369.